Search in sources :

Example 11 with JavaParserTypeSolver

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;
}
Also used : SourceFileInfoExtractor(com.github.javaparser.symbolsolver.SourceFileInfoExtractor) JavaParserTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.JavaParserTypeSolver) ReflectionTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver) CombinedTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver)

Example 12 with JavaParserTypeSolver

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;
}
Also used : JavaParserTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.JavaParserTypeSolver) ReflectionTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver) File(java.io.File) CombinedTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver)

Example 13 with JavaParserTypeSolver

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());
}
Also used : CompilationUnit(com.github.javaparser.ast.CompilationUnit) Context(com.github.javaparser.symbolsolver.core.resolution.Context) LambdaExprContext(com.github.javaparser.symbolsolver.javaparsermodel.contexts.LambdaExprContext) LambdaExpr(com.github.javaparser.ast.expr.LambdaExpr) CombinedTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver) VariableDeclarator(com.github.javaparser.ast.body.VariableDeclarator) LambdaExprContext(com.github.javaparser.symbolsolver.javaparsermodel.contexts.LambdaExprContext) Value(com.github.javaparser.symbolsolver.model.resolution.Value) JavaParserTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.JavaParserTypeSolver) ReflectionTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver) File(java.io.File) AbstractResolutionTest(com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest) Test(org.junit.Test)

Example 14 with JavaParserTypeSolver

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());
}
Also used : CompilationUnit(com.github.javaparser.ast.CompilationUnit) Context(com.github.javaparser.symbolsolver.core.resolution.Context) LambdaExprContext(com.github.javaparser.symbolsolver.javaparsermodel.contexts.LambdaExprContext) MethodDeclaration(com.github.javaparser.ast.body.MethodDeclaration) LambdaExpr(com.github.javaparser.ast.expr.LambdaExpr) CombinedTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver) VariableDeclarator(com.github.javaparser.ast.body.VariableDeclarator) LambdaExprContext(com.github.javaparser.symbolsolver.javaparsermodel.contexts.LambdaExprContext) Value(com.github.javaparser.symbolsolver.model.resolution.Value) JavaParserTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.JavaParserTypeSolver) ReflectionTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver) File(java.io.File) AbstractResolutionTest(com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest) Test(org.junit.Test)

Example 15 with JavaParserTypeSolver

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);
}
Also used : CompilationUnit(com.github.javaparser.ast.CompilationUnit) MethodDeclaration(com.github.javaparser.ast.body.MethodDeclaration) JavaParserTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.JavaParserTypeSolver) JavaParserFacade(com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade) ReflectionTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver) File(java.io.File) CombinedTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver) MethodCallExpr(com.github.javaparser.ast.expr.MethodCallExpr)

Aggregations

JavaParserTypeSolver (com.github.javaparser.symbolsolver.resolution.typesolvers.JavaParserTypeSolver)23 CombinedTypeSolver (com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver)22 ReflectionTypeSolver (com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver)22 File (java.io.File)20 CompilationUnit (com.github.javaparser.ast.CompilationUnit)9 Before (org.junit.Before)9 Test (org.junit.Test)8 TypeSolver (com.github.javaparser.symbolsolver.model.resolution.TypeSolver)6 AbstractResolutionTest (com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest)6 MethodDeclaration (com.github.javaparser.ast.body.MethodDeclaration)5 JavaParserFacade (com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade)4 ClassOrInterfaceDeclaration (com.github.javaparser.ast.body.ClassOrInterfaceDeclaration)3 VariableDeclarator (com.github.javaparser.ast.body.VariableDeclarator)3 MethodCallExpr (com.github.javaparser.ast.expr.MethodCallExpr)3 SourceFileInfoExtractor (com.github.javaparser.symbolsolver.SourceFileInfoExtractor)3 LambdaExpr (com.github.javaparser.ast.expr.LambdaExpr)2 ResolvedReferenceType (com.github.javaparser.resolution.types.ResolvedReferenceType)2 Context (com.github.javaparser.symbolsolver.core.resolution.Context)2 LambdaExprContext (com.github.javaparser.symbolsolver.javaparsermodel.contexts.LambdaExprContext)2 Value (com.github.javaparser.symbolsolver.model.resolution.Value)2