use of gumtree.spoon.diff.Diff in project dspot by STAMP-project.
the class SelectorOnDiff method pathToModifiedJavaFile.
private static Set<String> pathToModifiedJavaFile(String baseSha, String pathToChangedVersion) {
Process p;
try {
p = Runtime.getRuntime().exec("git diff " + baseSha, new String[] {}, new File(pathToChangedVersion));
} catch (IOException e) {
throw new RuntimeException(e);
}
final Set<String> modifiedJavaFiles = new BufferedReader(new InputStreamReader(p.getInputStream())).lines().filter(line -> line.startsWith("diff") && line.endsWith(".java")).map(line -> line.split(" ")[2]).collect(Collectors.toSet());
try {
p.waitFor();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
if (Main.verbose) {
LOGGER.info("Modified files:{}{}", AmplificationHelper.LINE_SEPARATOR, modifiedJavaFiles.stream().collect(Collectors.joining(AmplificationHelper.LINE_SEPARATOR)));
}
return modifiedJavaFiles;
}
use of gumtree.spoon.diff.Diff in project dspot by STAMP-project.
the class SelectorOnDiff method getModifiedMethod.
@SuppressWarnings("unchecked")
private static Set<CtMethod> getModifiedMethod(String pathFile1, String pathFile2) {
try {
final File file1 = new File(pathFile1);
final File file2 = new File(pathFile2);
if (!file1.exists() || !file2.exists()) {
return Collections.emptySet();
}
Diff result = (new AstComparator()).compare(file1, file2);
return result.getRootOperations().stream().map(operation -> operation.getSrcNode().getParent(CtMethod.class)).collect(Collectors.toSet());
} catch (Exception ignored) {
// if something bad happen, we do not care, we go for next file
return Collections.emptySet();
}
}
Aggregations