Search in sources :

Example 31 with CombinedTypeSolver

use of com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver in project javaparser by javaparser.

the class CompilationUnitContextResolutionTest method solveSymbolAsValueReferringToStaticallyImportedValue.

@Test
public void solveSymbolAsValueReferringToStaticallyImportedValue() throws ParseException, IOException {
    CompilationUnit cu = parseSample("CompilationUnitSymbols");
    Context context = new CompilationUnitContext(cu, typeSolver);
    CombinedTypeSolver typeSolver = new CombinedTypeSolver();
    typeSolver.add(new ReflectionTypeSolver());
    typeSolver.add(new JarTypeSolver(adaptPath("src/test/resources/junit-4.8.1.jar")));
    Optional<Value> ref = context.solveSymbolAsValue("out", typeSolver);
    assertEquals(true, ref.isPresent());
    assertEquals("java.io.PrintStream", ref.get().getType().describe());
}
Also used : CompilationUnit(com.github.javaparser.ast.CompilationUnit) Context(com.github.javaparser.symbolsolver.core.resolution.Context) CompilationUnitContext(com.github.javaparser.symbolsolver.javaparsermodel.contexts.CompilationUnitContext) CompilationUnitContext(com.github.javaparser.symbolsolver.javaparsermodel.contexts.CompilationUnitContext) Value(com.github.javaparser.symbolsolver.model.resolution.Value) JarTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.JarTypeSolver) ReflectionTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver) CombinedTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver) AbstractResolutionTest(com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest) Test(org.junit.Test)

Example 32 with CombinedTypeSolver

use of com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver in project javaparser by javaparser.

the class JavaParserAnonymousClassDeclarationTest method callingAnonymousClassInnerMethod.

@Test
public void callingAnonymousClassInnerMethod() {
    CompilationUnit cu = parseSample("AnonymousClassDeclarations");
    ClassOrInterfaceDeclaration aClass = Navigator.demandClass(cu, "AnonymousClassDeclarations");
    MethodDeclaration method = Navigator.demandMethod(aClass, "fooBar3");
    MethodCallExpr methodCall = Navigator.findMethodCall(method, "callAnnonClassInnerMethod").get();
    CombinedTypeSolver combinedTypeSolver = new CombinedTypeSolver();
    combinedTypeSolver.add(new ReflectionTypeSolver());
    MethodUsage methodUsage = JavaParserFacade.get(combinedTypeSolver).solveMethodAsUsage(methodCall);
    assertTrue(methodUsage.getQualifiedSignature().startsWith("AnonymousClassDeclarations"));
    assertTrue(methodUsage.getQualifiedSignature().contains("Anonymous-"));
    assertTrue(methodUsage.getQualifiedSignature().endsWith("callAnnonClassInnerMethod()"));
}
Also used : CompilationUnit(com.github.javaparser.ast.CompilationUnit) ClassOrInterfaceDeclaration(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration) MethodDeclaration(com.github.javaparser.ast.body.MethodDeclaration) MethodUsage(com.github.javaparser.resolution.MethodUsage) ReflectionTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver) CombinedTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver) MethodCallExpr(com.github.javaparser.ast.expr.MethodCallExpr) AbstractResolutionTest(com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest) Test(org.junit.Test)

Example 33 with CombinedTypeSolver

use of com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver in project javaparser by javaparser.

the class JavaParserAnonymousClassDeclarationTest method anonymousClassAsMethodArgument.

@Test
public void anonymousClassAsMethodArgument() {
    CompilationUnit cu = parseSample("AnonymousClassDeclarations");
    ClassOrInterfaceDeclaration aClass = Navigator.demandClass(cu, "AnonymousClassDeclarations");
    MethodDeclaration method = Navigator.demandMethod(aClass, "fooBar1");
    MethodCallExpr methodCall = Navigator.findMethodCall(method, "of").get();
    CombinedTypeSolver combinedTypeSolver = new CombinedTypeSolver();
    combinedTypeSolver.add(new ReflectionTypeSolver());
    MethodUsage methodUsage = JavaParserFacade.get(combinedTypeSolver).solveMethodAsUsage(methodCall);
    assertThat(methodUsage.getQualifiedSignature(), is("AnonymousClassDeclarations.ParDo.of(AnonymousClassDeclarations.DoFn<I, O>)"));
}
Also used : CompilationUnit(com.github.javaparser.ast.CompilationUnit) ClassOrInterfaceDeclaration(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration) MethodDeclaration(com.github.javaparser.ast.body.MethodDeclaration) MethodUsage(com.github.javaparser.resolution.MethodUsage) ReflectionTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver) CombinedTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver) MethodCallExpr(com.github.javaparser.ast.expr.MethodCallExpr) AbstractResolutionTest(com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest) Test(org.junit.Test)

Example 34 with CombinedTypeSolver

use of com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver in project javaparser by javaparser.

the class JavaParserAnonymousClassDeclarationTest method usingAnonymousSuperClassInnerType.

@Test
public void usingAnonymousSuperClassInnerType() {
    CompilationUnit cu = parseSample("AnonymousClassDeclarations");
    ClassOrInterfaceDeclaration aClass = Navigator.demandClass(cu, "AnonymousClassDeclarations");
    MethodDeclaration method = Navigator.demandMethod(aClass, "fooBar4");
    MethodCallExpr methodCall = Navigator.findMethodCall(method, "toString").get();
    CombinedTypeSolver combinedTypeSolver = new CombinedTypeSolver();
    combinedTypeSolver.add(new ReflectionTypeSolver());
    MethodUsage methodUsage = JavaParserFacade.get(combinedTypeSolver).solveMethodAsUsage(methodCall);
    assertThat(methodUsage.getQualifiedSignature(), is("java.lang.Enum.toString()"));
}
Also used : CompilationUnit(com.github.javaparser.ast.CompilationUnit) ClassOrInterfaceDeclaration(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration) MethodDeclaration(com.github.javaparser.ast.body.MethodDeclaration) MethodUsage(com.github.javaparser.resolution.MethodUsage) ReflectionTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver) CombinedTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver) MethodCallExpr(com.github.javaparser.ast.expr.MethodCallExpr) AbstractResolutionTest(com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest) Test(org.junit.Test)

Example 35 with CombinedTypeSolver

use of com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver in project javaparser by javaparser.

the class JavaParserAnonymousClassDeclarationTest method usingAnonymousClassInnerType.

@Test
public void usingAnonymousClassInnerType() {
    CompilationUnit cu = parseSample("AnonymousClassDeclarations");
    ClassOrInterfaceDeclaration aClass = Navigator.demandClass(cu, "AnonymousClassDeclarations");
    MethodDeclaration method = Navigator.demandMethod(aClass, "fooBar5");
    MethodCallExpr methodCall = Navigator.findMethodCall(method, "toString").get();
    CombinedTypeSolver combinedTypeSolver = new CombinedTypeSolver();
    combinedTypeSolver.add(new ReflectionTypeSolver());
    MethodUsage methodUsage = JavaParserFacade.get(combinedTypeSolver).solveMethodAsUsage(methodCall);
    assertThat(methodUsage.getQualifiedSignature(), is("java.lang.Enum.toString()"));
}
Also used : CompilationUnit(com.github.javaparser.ast.CompilationUnit) ClassOrInterfaceDeclaration(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration) MethodDeclaration(com.github.javaparser.ast.body.MethodDeclaration) MethodUsage(com.github.javaparser.resolution.MethodUsage) ReflectionTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver) CombinedTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver) MethodCallExpr(com.github.javaparser.ast.expr.MethodCallExpr) AbstractResolutionTest(com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest) Test(org.junit.Test)

Aggregations

CombinedTypeSolver (com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver)49 ReflectionTypeSolver (com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver)46 CompilationUnit (com.github.javaparser.ast.CompilationUnit)23 JavaParserTypeSolver (com.github.javaparser.symbolsolver.resolution.typesolvers.JavaParserTypeSolver)22 Test (org.junit.Test)21 File (java.io.File)20 AbstractResolutionTest (com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest)19 JarTypeSolver (com.github.javaparser.symbolsolver.resolution.typesolvers.JarTypeSolver)15 Before (org.junit.Before)15 MethodCallExpr (com.github.javaparser.ast.expr.MethodCallExpr)12 MethodDeclaration (com.github.javaparser.ast.body.MethodDeclaration)11 ClassOrInterfaceDeclaration (com.github.javaparser.ast.body.ClassOrInterfaceDeclaration)9 MethodUsage (com.github.javaparser.resolution.MethodUsage)9 Context (com.github.javaparser.symbolsolver.core.resolution.Context)9 JavaParserFacade (com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade)6 CompilationUnitContext (com.github.javaparser.symbolsolver.javaparsermodel.contexts.CompilationUnitContext)6 TypeSolver (com.github.javaparser.symbolsolver.model.resolution.TypeSolver)6 Value (com.github.javaparser.symbolsolver.model.resolution.Value)4 VariableDeclarator (com.github.javaparser.ast.body.VariableDeclarator)3 SourceFileInfoExtractor (com.github.javaparser.symbolsolver.SourceFileInfoExtractor)3