use of com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver in project javaparser by javaparser.
the class SymbolSolverWithJavassistInterfaceTest method setup.
@Before
public void setup() throws IOException {
final String pathToMainJar = adaptPath("src/test/resources/javassist_symbols/main_jar/main_jar.jar");
final String pathToIncludedJar = adaptPath("src/test/resources/javassist_symbols/included_jar/included_jar.jar");
typeSolver = new CombinedTypeSolver(new JarTypeSolver(pathToIncludedJar), new JarTypeSolver(pathToMainJar), new ReflectionTypeSolver());
symbolSolver = new SymbolSolver(typeSolver);
interfaceDeclarationStandalone = (JavassistInterfaceDeclaration) typeSolver.solveType("com.github.javaparser.javasymbolsolver.javassist_symbols.main_jar.StandaloneInterface");
interfaceDeclarationSubInterfaceOwnJar = (JavassistInterfaceDeclaration) typeSolver.solveType("com.github.javaparser.javasymbolsolver.javassist_symbols.main_jar.SubInterfaceOwnJar");
interfaceDeclarationSubInterfaceIncludedJar = (JavassistInterfaceDeclaration) typeSolver.solveType("com.github.javaparser.javasymbolsolver.javassist_symbols.main_jar.SubInterfaceIncludedJar");
interfaceDeclarationSubInterfaceExcludedJar = (JavassistInterfaceDeclaration) typeSolver.solveType("com.github.javaparser.javasymbolsolver.javassist_symbols.main_jar.SubInterfaceExcludedJar");
}
use of com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver in project javaparser by javaparser.
the class LambdaExprContextResolutionTest method solveParameterOfLambdaInFieldDecl.
@Test
public void solveParameterOfLambdaInFieldDecl() {
CompilationUnit cu = parseSample("Lambda");
com.github.javaparser.ast.body.ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "Agenda");
VariableDeclarator field = Navigator.demandField(clazz, "functional");
LambdaExpr lambdaExpr = (LambdaExpr) field.getInitializer().get();
File src = new File("src/test/resources");
CombinedTypeSolver combinedTypeSolver = new CombinedTypeSolver();
combinedTypeSolver.add(new ReflectionTypeSolver());
combinedTypeSolver.add(new JavaParserTypeSolver(adaptPath(src)));
Context context = new LambdaExprContext(lambdaExpr, combinedTypeSolver);
Optional<Value> ref = context.solveSymbolAsValue("p", typeSolver);
assertTrue(ref.isPresent());
assertEquals("java.lang.String", ref.get().getType().describe());
}
use of com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver in project javaparser by javaparser.
the class LambdaExprContextResolutionTest method solveParameterOfLambdaInVarDecl.
@Test
public void solveParameterOfLambdaInVarDecl() {
CompilationUnit cu = parseSample("Lambda");
com.github.javaparser.ast.body.ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "Agenda");
MethodDeclaration method = Navigator.demandMethod(clazz, "testFunctionalVar");
VariableDeclarator varDecl = Navigator.demandVariableDeclaration(method, "a").get();
LambdaExpr lambdaExpr = (LambdaExpr) varDecl.getInitializer().get();
File src = adaptPath(new File("src/test/resources"));
CombinedTypeSolver combinedTypeSolver = new CombinedTypeSolver();
combinedTypeSolver.add(new ReflectionTypeSolver());
combinedTypeSolver.add(new JavaParserTypeSolver(src));
Context context = new LambdaExprContext(lambdaExpr, combinedTypeSolver);
Optional<Value> ref = context.solveSymbolAsValue("p", typeSolver);
assertTrue(ref.isPresent());
assertEquals("java.lang.String", ref.get().getType().describe());
}
use of com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver in project javaparser by javaparser.
the class MethodCallExprContextResolutionTest method assertCanSolveGenericMethodCallMustUseProvidedTypeArgs.
private void assertCanSolveGenericMethodCallMustUseProvidedTypeArgs(String callMethodName) {
MethodCallExpr methodCallExpr = getMethodCallExpr("genericMethodTest", callMethodName);
CombinedTypeSolver typeSolver = createTypeSolver();
MethodCallExprContext context = new MethodCallExprContext(methodCallExpr, typeSolver);
Optional<MethodUsage> ref = context.solveMethodAsUsage(callMethodName, Collections.emptyList(), typeSolver);
assertTrue(ref.isPresent());
assertEquals("MethodCalls", ref.get().declaringType().getQualifiedName());
assertEquals(Collections.singletonList("java.lang.Integer"), ref.get().typeParametersMap().getTypes().stream().map(ty -> ty.asReferenceType().describe()).collect(Collectors.toList()));
}
use of com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver in project javaparser by javaparser.
the class Widget method main.
public static void main(String[] args) throws IOException, ParseException {
File src = new File(JAVA_ROOT);
CombinedTypeSolver combinedTypeSolver = new CombinedTypeSolver();
combinedTypeSolver.add(new ReflectionTypeSolver(true));
combinedTypeSolver.add(new JavaParserTypeSolver(src));
CompilationUnit compilationUnit = JavaParser.parse(new File(CLASS));
JavaParserFacade parserFacade = JavaParserFacade.get(combinedTypeSolver);
MethodDeclaration methodDeclaration = compilationUnit.getNodesByType(MethodDeclaration.class).stream().filter(node -> node.getName().equals("doSomething")).findAny().orElse(null);
methodDeclaration.getNodesByType(MethodCallExpr.class).forEach(parserFacade::solve);
}
Aggregations