|
|
@ -13,8 +13,8 @@ import ru.ulstu.extractor.heuristic.api.StructuralUnitIdentifier;
|
|
|
|
import ru.ulstu.extractor.heuristic.component.BuildTool;
|
|
|
|
import ru.ulstu.extractor.heuristic.component.BuildTool;
|
|
|
|
import ru.ulstu.extractor.heuristic.component.JavaProgrammingLanguage;
|
|
|
|
import ru.ulstu.extractor.heuristic.component.JavaProgrammingLanguage;
|
|
|
|
import ru.ulstu.extractor.heuristic.component.ProgrammingLanguage;
|
|
|
|
import ru.ulstu.extractor.heuristic.component.ProgrammingLanguage;
|
|
|
|
|
|
|
|
import ru.ulstu.extractor.heuristic.model.BusinessLogicUnit;
|
|
|
|
import ru.ulstu.extractor.heuristic.model.EntityUnit;
|
|
|
|
import ru.ulstu.extractor.heuristic.model.EntityUnit;
|
|
|
|
import ru.ulstu.extractor.heuristic.model.StructuralUnit;
|
|
|
|
|
|
|
|
import ru.ulstu.extractor.util.StringUtils;
|
|
|
|
import ru.ulstu.extractor.util.StringUtils;
|
|
|
|
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
import java.io.File;
|
|
|
@ -29,6 +29,7 @@ import static ru.ulstu.extractor.heuristic.service.DetectorService.LangDetectScr
|
|
|
|
@Service
|
|
|
|
@Service
|
|
|
|
public class JavaIdentifier extends StructuralUnitIdentifier {
|
|
|
|
public class JavaIdentifier extends StructuralUnitIdentifier {
|
|
|
|
private static final String ENTITY_ANNOTATION = "@Entity";
|
|
|
|
private static final String ENTITY_ANNOTATION = "@Entity";
|
|
|
|
|
|
|
|
private static final String SERVICE_ANNOTATION = "@Service";
|
|
|
|
private final DetectorService detectorService;
|
|
|
|
private final DetectorService detectorService;
|
|
|
|
private final BuildToolService buildToolService;
|
|
|
|
private final BuildToolService buildToolService;
|
|
|
|
private final ProgrammingLanguageService programmingLanguageService;
|
|
|
|
private final ProgrammingLanguageService programmingLanguageService;
|
|
|
@ -56,7 +57,7 @@ public class JavaIdentifier extends StructuralUnitIdentifier {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public List<StructuralUnit> getEntityClasses(String projectPath, String subDirectory, List<File> projectFiles) {
|
|
|
|
public List<EntityUnit> getEntityClasses(String projectPath, String subDirectory, List<File> projectFiles) {
|
|
|
|
return projectFiles.stream()
|
|
|
|
return projectFiles.stream()
|
|
|
|
.filter(file -> StringUtils.fileInSubdirectory(file.getPath(), projectPath, subDirectory))
|
|
|
|
.filter(file -> StringUtils.fileInSubdirectory(file.getPath(), projectPath, subDirectory))
|
|
|
|
.filter(this::isEntityClass)
|
|
|
|
.filter(this::isEntityClass)
|
|
|
@ -64,15 +65,14 @@ public class JavaIdentifier extends StructuralUnitIdentifier {
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected Optional<ProgrammingLanguage> getMainProgrammingLanguage(String sourceCode) {
|
|
|
|
|
|
|
|
return sourceCodeContainsClass(sourceCode)
|
|
|
|
|
|
|
|
? Optional.of(getProgrammingLanguage())
|
|
|
|
|
|
|
|
: Optional.empty();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public List<StructuralUnit> getBusinessLogicClasses() {
|
|
|
|
public List<BusinessLogicUnit> getBusinessLogicClasses(String projectPath, String subDirectory, List<File> projectFiles) {
|
|
|
|
return null;
|
|
|
|
return projectFiles.stream()
|
|
|
|
|
|
|
|
.filter(file -> StringUtils.fileInSubdirectory(file.getPath(), projectPath, subDirectory))
|
|
|
|
|
|
|
|
.filter(this::isBusinessLogicClass)
|
|
|
|
|
|
|
|
.map(file -> new BusinessLogicUnit(projectPath, file))
|
|
|
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
@ -85,6 +85,12 @@ public class JavaIdentifier extends StructuralUnitIdentifier {
|
|
|
|
return buildToolService.getProjectBuildTool(rootDirectoryFiles);
|
|
|
|
return buildToolService.getProjectBuildTool(rootDirectoryFiles);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected Optional<ProgrammingLanguage> getMainProgrammingLanguage(String sourceCode) {
|
|
|
|
|
|
|
|
return sourceCodeContainsClass(sourceCode)
|
|
|
|
|
|
|
|
? Optional.of(getProgrammingLanguage())
|
|
|
|
|
|
|
|
: Optional.empty();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
protected DetectorService getDetectorService() {
|
|
|
|
protected DetectorService getDetectorService() {
|
|
|
|
return detectorService;
|
|
|
|
return detectorService;
|
|
|
@ -120,6 +126,16 @@ public class JavaIdentifier extends StructuralUnitIdentifier {
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public boolean isBusinessLogicClass(String sourceCode) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
return classContainsAnnotation(sourceCode, SERVICE_ANNOTATION);
|
|
|
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
|
|
|
ex.printStackTrace();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private boolean classContainsAnnotation(File file, String annotationDeclaration) throws IOException {
|
|
|
|
private boolean classContainsAnnotation(File file, String annotationDeclaration) throws IOException {
|
|
|
|
return classContainsAnnotation(new String(Files.readAllBytes(file.toPath())), annotationDeclaration);
|
|
|
|
return classContainsAnnotation(new String(Files.readAllBytes(file.toPath())), annotationDeclaration);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -152,6 +168,11 @@ public class JavaIdentifier extends StructuralUnitIdentifier {
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
protected boolean isBusinessLogicClass(File file) {
|
|
|
|
protected boolean isBusinessLogicClass(File file) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
return file.getName().endsWith("java") && classContainsAnnotation(file, SERVICE_ANNOTATION);
|
|
|
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
|
|
|
ex.printStackTrace();
|
|
|
|
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|