analyze-java-code-examples
analyze-java-code-examples copied to clipboard
ListClassesExample gives compile error on newest version of JavaParser
Hello,
First of all thank you for making this guide! However, when I try to implement your code I run into an error concerning the JavaParser parse function Specifically in the listClasses method:
new DirExplorer((level, path, file) -> path.endsWith(".java"), (level, path, file) -> {
System.out.println(path);
System.out.println(Strings.repeat("=", path.length()));
try {
new VoidVisitorAdapter<Object>() {
@Override
public void visit(ClassOrInterfaceDeclaration n, Object arg) {
super.visit(n, arg);
System.out.println(" * " + n.getName());
}
}.visit(JavaParser.parse(file), null);
System.out.println(); // empty line
} catch (ParseException | IOException e) {
new RuntimeException(e);
}
}).explore(projectDir);
}
the function call to visit(JavaParser.parse(file), null) gives a Non-static method 'parse(java.io.File, java.nio.charset.Charset)' cannot be referenced from a static context error.
Could this be due to compatibility errors due to versioning?
Hi Daniel, that could the case indeed as JavaParser changed over time. I would try using some old version of JavaParser or adapt it. The people on the gitter channel of JavaParser may help