#12 -- Add base classes for heuristic

This commit is contained in:
Anton Romanov 2021-03-25 09:21:58 +04:00
parent 4af08bc9b8
commit 5730954c13
8 changed files with 155 additions and 0 deletions

View File

@ -0,0 +1,23 @@
package ru.ulstu.extractor.heuristic.api;
import ru.ulstu.extractor.heuristic.model.BuildTool;
import ru.ulstu.extractor.heuristic.model.ProgrammingLanguage;
import ru.ulstu.extractor.heuristic.model.StructuralUnit;
import java.util.List;
public interface StructuralUnitIdentifier {
List<StructuralUnit> getEntityClasses();
List<StructuralUnit> getBusinessLogicClasses();
ProgrammingLanguage getMainProgrammingLanguage();
boolean isMultiModuleProject();
BuildTool getBuildTool();
default boolean canAppliedToProject() {
return false;
}
}

View File

@ -0,0 +1,16 @@
package ru.ulstu.extractor.heuristic.model;
public abstract class BuildTool {
private final String name;
public BuildTool(String name) {
this.name = name;
}
protected abstract boolean canAppliedToProject();
public String getName() {
return name;
}
}

View File

@ -0,0 +1,13 @@
package ru.ulstu.extractor.heuristic.model;
public class GradleBuildTool extends BuildTool {
public GradleBuildTool() {
super("Gradle");
}
@Override
protected boolean canAppliedToProject() {
return false;
}
}

View File

@ -0,0 +1,7 @@
package ru.ulstu.extractor.heuristic.model;
public class JavaProgrammingLanguage extends ProgrammingLanguage {
public JavaProgrammingLanguage() {
super("Java");
}
}

View File

@ -0,0 +1,13 @@
package ru.ulstu.extractor.heuristic.model;
public abstract class ProgrammingLanguage {
private final String name;
public ProgrammingLanguage(String name) {
this.name = name;
}
public String getName() {
return name;
}
}

View File

@ -0,0 +1,14 @@
package ru.ulstu.extractor.heuristic.model;
public abstract class StructuralUnit {
private String pathToFile;
private String moduleName;
public String getPathToFile() {
return pathToFile;
}
public String getModuleName() {
return moduleName;
}
}

View File

@ -0,0 +1,45 @@
package ru.ulstu.extractor.heuristic.service;
import org.springframework.stereotype.Service;
import ru.ulstu.extractor.heuristic.api.StructuralUnitIdentifier;
import ru.ulstu.extractor.heuristic.model.BuildTool;
import ru.ulstu.extractor.heuristic.model.GradleBuildTool;
import ru.ulstu.extractor.heuristic.model.JavaProgrammingLanguage;
import ru.ulstu.extractor.heuristic.model.ProgrammingLanguage;
import ru.ulstu.extractor.heuristic.model.StructuralUnit;
import java.util.List;
@Service
public class JavaIdentifier implements StructuralUnitIdentifier {
@Override
public boolean canAppliedToProject() {
return getBuildTool() instanceof GradleBuildTool
&& getMainProgrammingLanguage() instanceof JavaProgrammingLanguage;
}
@Override
public List<StructuralUnit> getEntityClasses() {
return null;
}
@Override
public List<StructuralUnit> getBusinessLogicClasses() {
return null;
}
@Override
public ProgrammingLanguage getMainProgrammingLanguage() {
return null;
}
@Override
public boolean isMultiModuleProject() {
return false;
}
@Override
public BuildTool getBuildTool() {
return null;
}
}

View File

@ -0,0 +1,24 @@
package ru.ulstu.extractor.heuristic.service;
import org.springframework.stereotype.Service;
import ru.ulstu.extractor.heuristic.api.StructuralUnitIdentifier;
import ru.ulstu.extractor.heuristic.model.StructuralUnit;
import java.util.List;
@Service
public class StructuralUnitService {
private final List<StructuralUnitIdentifier> structuralUnitIdentifiers;
public StructuralUnitService(List<StructuralUnitIdentifier> structuralUnitIdentifiers) {
this.structuralUnitIdentifiers = structuralUnitIdentifiers;
}
public List<StructuralUnit> getEntities() {
StructuralUnitIdentifier selectedIdentifier = structuralUnitIdentifiers.stream()
.filter(StructuralUnitIdentifier::canAppliedToProject)
.findAny()
.orElseThrow(() -> new RuntimeException("Identifier not found"));
return selectedIdentifier.getEntityClasses();
}
}