I want to analyze dependencies among classes which I have started using JavaParser and it's SymbolResolver for. But it keeps failing when resolving several of the method references on a sample project from Eclipse Scout. Scout uses it's own BEAN manager where it loads java classes at jvm startup into a list which makes it more flexible to load and unload classes at runtime. But Eclipse IDE is able to resolve the dependencies somehow. Here is my working example which I use for parsing the Eclipse Scout project:
private static String getFullyQualifiedName(MethodCallExpr exp) {
String result = "";
try {
result = exp.getName() + " --> " + exp.resolve().getQualifiedSignature();
} catch (RuntimeException e) {
result = "!unable to resolve! " + exp.getName();
}
return result;
}
private static void runAnalysis(String sourceFolder) {
final ProjectRoot projectRoot = new SymbolSolverCollectionStrategy().collect(new File(sourceFolder).toPath());
projectRoot.getSourceRoots().forEach(sourceRoot -> sourceRoot.tryToParseParallelized()
.forEach(parsedSource -> parsedSource.getResult().get().findAll(MethodCallExpr.class)
.forEach(exp -> System.out.println(parsedSource.getResult().get().getPackageDeclaration().get().getNameAsString()
+ "." + parsedSource.getResult().get().getStorage().get().getFileName()
+ " (" + exp.getBegin().get().line + ") "
+ getFullyQualifiedName(exp)))));
}
I add all maven dependency JAR's to the source root folder as well as all the source code and I am just using a plain helloworld example from Scout. To me it seems quite random why and when it works vs. when it fails to resolve the MethodCallEx. Java Symbol Solver is even able to resolve some of the BEAN.get() dependencies which is nice.
A successful output looks like this:
scout.ui.html.UiServletFilter.java (66) destroy --> org.eclipse.scout.rt.server.commons.authentication.DevelopmentAccessController.destroy()
And a failed output like that:
scout.server.helloworld.HelloWorldService.java (15) !unable to resolve! getUserId
But Eclipse IDE is able to resolve all classes and method calls.