Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import static net.sourceforge.pmd.RuleViolation.CLASS_NAME;
import static net.sourceforge.pmd.RuleViolation.PACKAGE_NAME;

import com.github.javaparser.ParserConfiguration;
import com.github.javaparser.StaticJavaParser;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
Expand Down Expand Up @@ -59,6 +61,7 @@ public CostBenefitCalculator(String repositoryPath) {
}

public List<RankedCycle> runCycleAnalysis(String outputDirectoryPath, boolean renderImages) {
StaticJavaParser.getParserConfiguration().setLanguageLevel(ParserConfiguration.LanguageLevel.BLEEDING_EDGE);
List<RankedCycle> rankedCycles = new ArrayList<>();
try {
Map<String, String> classNamesAndPaths = getClassNamesAndPaths();
Expand Down Expand Up @@ -296,7 +299,15 @@ private List<CBOClass> getCBOClasses() {
}

private String getFileName(RuleViolation violation) {
return violation.getFileId().getUriString().replace("file:///" + repositoryPath.replace("\\", "/") + "/", "");
String uriString = violation.getFileId().getUriString();
return canonicaliseURIStringForRepoLookup(uriString);
}

private String canonicaliseURIStringForRepoLookup(String uriString) {
if (repositoryPath.startsWith("/") || repositoryPath.startsWith("\\")) {
return uriString.replace("file://" + repositoryPath.replace("\\", "/") + "/", "");
}
return uriString.replace("file:///" + repositoryPath.replace("\\", "/") + "/", "");
}

public Map<String, String> getClassNamesAndPaths() throws IOException {
Expand All @@ -307,9 +318,8 @@ public Map<String, String> getClassNamesAndPaths() throws IOException {
walk.forEach(path -> {
String filename = path.getFileName().toString();
if (filename.endsWith(".java")) {
fileNamePaths.put(
getClassName(filename),
path.toUri().toString().replace("file:///" + repositoryPath.replace("\\", "/") + "/", ""));
String uriString = path.toUri().toString();
fileNamePaths.put(getClassName(filename), canonicaliseURIStringForRepoLookup(uriString));
}
});
}
Expand Down