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.
Does your analysis happen at runtime or in the IDE based on the source-code? The former would be a question about the Scout runtime and the BeanManager which is used when BEANS is called, the latter is a question about the Scout SDK, which you can download here: Eclipse IDE for Scout Developers.
I assume you want to analyze the source-code. When you download the Eclipse package mentioned above, you get the Eclipse IDE with additional plugins for Eclipse Scout. These plugins use tools provided by the Eclipse platform to analyze Scout classes. So I'd suggest you take a look at the Eclipse Scout SDK source-code and use the same tools for your analysis. Make sure you choose the release branch that matches the version of your Scout project.