use of com.github.javaparser.symbolsolver.resolution.typesolvers.JavaParserTypeSolver in project javaparser by javaparser.
the class AnalyseJavaParserTest method getSourceFileInfoExtractor.
private SourceFileInfoExtractor getSourceFileInfoExtractor() {
CombinedTypeSolver combinedTypeSolver = new CombinedTypeSolver();
combinedTypeSolver.add(new ReflectionTypeSolver());
combinedTypeSolver.add(new JavaParserTypeSolver(src));
combinedTypeSolver.add(new JavaParserTypeSolver(adaptPath(new File("src/test/test_sourcecode/javaparser_src/generated"))));
SourceFileInfoExtractor sourceFileInfoExtractor = new SourceFileInfoExtractor();
sourceFileInfoExtractor.setTypeSolver(combinedTypeSolver);
sourceFileInfoExtractor.setPrintFileName(false);
return sourceFileInfoExtractor;
}
use of com.github.javaparser.symbolsolver.resolution.typesolvers.JavaParserTypeSolver in project javaparser by javaparser.
the class AnalyseNewJavaParserHelpersTest method typeSolver.
private static TypeSolver typeSolver() {
CombinedTypeSolver combinedTypeSolver = new CombinedTypeSolver();
combinedTypeSolver.add(new ReflectionTypeSolver());
combinedTypeSolver.add(new JavaParserTypeSolver(src));
combinedTypeSolver.add(new JavaParserTypeSolver(adaptPath(new File("src/test/test_sourcecode/javaparser_new_src/javaparser-generated-sources"))));
return combinedTypeSolver;
}
use of com.github.javaparser.symbolsolver.resolution.typesolvers.JavaParserTypeSolver 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.JavaParserTypeSolver 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.JavaParserTypeSolver 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