| 1 |
/** |
| 2 |
* (C) 2016 Agilysys NV, LLC. All Rights Reserved. Confidential Information of Agilysys NV, LLC. |
| 3 |
*/ |
| 4 |
package com.foo; |
| 5 |
|
| 6 |
import java.io.File; |
| 7 |
import java.io.IOException; |
| 8 |
|
| 9 |
import com.github.javaparser.JavaParser; |
| 10 |
import com.github.javaparser.ParseException; |
| 11 |
import com.github.javaparser.ast.CompilationUnit; |
| 12 |
import com.github.javaparser.ast.body.MethodDeclaration; |
| 13 |
import com.github.javaparser.ast.expr.MethodCallExpr; |
| 14 |
import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; |
| 15 |
import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver; |
| 16 |
import com.github.javaparser.symbolsolver.resolution.typesolvers.JavaParserTypeSolver; |
| 17 |
import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; |
| 18 |
|
| 19 |
public class Widget extends com.foo.base.Widget { |
| 20 |
private static final String PROJECT_ROOT = "/Users/peloquina/dev/javasymbolsolver-issue"; |
| 21 |
private static final String JAVA_ROOT = PROJECT_ROOT + "/src/main/java"; |
| 22 |
private static final String CLASS = JAVA_ROOT + "/com/foo/Widget.java"; |
| 23 |
|
| 24 |
public static void main(String[] args) throws IOException, ParseException { |
| 25 |
File src = new File(JAVA_ROOT); |
| 26 |
CombinedTypeSolver combinedTypeSolver = new CombinedTypeSolver(); |
| 27 |
combinedTypeSolver.add(new ReflectionTypeSolver(true)); |
| 28 |
combinedTypeSolver.add(new JavaParserTypeSolver(src)); |
| 29 |
|
| 30 |
CompilationUnit compilationUnit = JavaParser.parse(new File(CLASS)); |
| 31 |
|
| 32 |
JavaParserFacade parserFacade = JavaParserFacade.get(combinedTypeSolver); |
| 33 |
MethodDeclaration methodDeclaration = compilationUnit.getNodesByType(MethodDeclaration.class).stream() |
| 34 |
.filter(node -> node.getName().equals("doSomething")).findAny().orElse(null); |
| 35 |
methodDeclaration.getNodesByType(MethodCallExpr.class).forEach(parserFacade::solve); |
| 36 |
} |
| 37 |
|
| 38 |
public void doSomething() { |
| 39 |
doSomethingMore(new Widget()); |
| 40 |
} |
| 41 |
|
| 42 |
public void doSomethingMore(Widget value) { |
| 43 |
// does something |
| 44 |
} |
| 45 |
} |