Search in sources :

Example 1 with MethodContext

use of com.github.javaparser.symbolsolver.javaparsermodel.contexts.MethodContext in project javaparser by javaparser.

the class Issue276 method testSolveStaticallyImportedMemberType.

@Test
public void testSolveStaticallyImportedMemberType() throws FileNotFoundException {
    CompilationUnit cu = JavaParser.parse(new File(adaptPath("src/test/resources/issue276/foo/C.java")));
    ClassOrInterfaceDeclaration cls = Navigator.demandClassOrInterface(cu, "C");
    TypeSolver typeSolver = new CombinedTypeSolver(new ReflectionTypeSolver(), new JavaParserTypeSolver(adaptPath(new File("src/test/resources/issue276"))));
    List<MethodDeclaration> methods = cls.findAll(MethodDeclaration.class);
    boolean isSolved = false;
    for (MethodDeclaration method : methods) {
        if (method.getNameAsString().equals("overrideMe")) {
            MethodContext context = new MethodContext(method, typeSolver);
            isSolved = context.solveType("FindMeIfYouCan", typeSolver).isSolved();
        }
    }
    Assert.assertTrue(isSolved);
}
Also used : CompilationUnit(com.github.javaparser.ast.CompilationUnit) ClassOrInterfaceDeclaration(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration) JavaParserTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.JavaParserTypeSolver) TypeSolver(com.github.javaparser.symbolsolver.model.resolution.TypeSolver) CombinedTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver) ReflectionTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver) MethodDeclaration(com.github.javaparser.ast.body.MethodDeclaration) MethodContext(com.github.javaparser.symbolsolver.javaparsermodel.contexts.MethodContext) 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) AbstractResolutionTest(com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest) Test(org.junit.Test)

Example 2 with MethodContext

use of com.github.javaparser.symbolsolver.javaparsermodel.contexts.MethodContext in project javaparser by javaparser.

the class MethodContextResolutionTest method solveTypeRefToLocalClass.

@Test
public void solveTypeRefToLocalClass() {
    CompilationUnit cu = parseSample("MethodWithTypes");
    ClassOrInterfaceDeclaration cd = Navigator.demandClass(cu, "Main");
    MethodDeclaration md = Navigator.demandMethod(cd, "methodWithLocalTypes");
    Context context = new MethodContext(md, typeSolver);
    SymbolReference<ResolvedTypeDeclaration> ref = context.solveType("LocalClass", new MemoryTypeSolver());
    assertEquals(true, ref.isSolved());
}
Also used : CompilationUnit(com.github.javaparser.ast.CompilationUnit) MethodContext(com.github.javaparser.symbolsolver.javaparsermodel.contexts.MethodContext) Context(com.github.javaparser.symbolsolver.core.resolution.Context) MemoryTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.MemoryTypeSolver) ClassOrInterfaceDeclaration(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration) MethodDeclaration(com.github.javaparser.ast.body.MethodDeclaration) MethodContext(com.github.javaparser.symbolsolver.javaparsermodel.contexts.MethodContext) ResolvedTypeDeclaration(com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration) AbstractResolutionTest(com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest) Test(org.junit.Test)

Aggregations

CompilationUnit (com.github.javaparser.ast.CompilationUnit)2 ClassOrInterfaceDeclaration (com.github.javaparser.ast.body.ClassOrInterfaceDeclaration)2 MethodDeclaration (com.github.javaparser.ast.body.MethodDeclaration)2 MethodContext (com.github.javaparser.symbolsolver.javaparsermodel.contexts.MethodContext)2 AbstractResolutionTest (com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest)2 Test (org.junit.Test)2 ResolvedTypeDeclaration (com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration)1 Context (com.github.javaparser.symbolsolver.core.resolution.Context)1 TypeSolver (com.github.javaparser.symbolsolver.model.resolution.TypeSolver)1 CombinedTypeSolver (com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver)1 JavaParserTypeSolver (com.github.javaparser.symbolsolver.resolution.typesolvers.JavaParserTypeSolver)1 MemoryTypeSolver (com.github.javaparser.symbolsolver.resolution.typesolvers.MemoryTypeSolver)1 ReflectionTypeSolver (com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver)1 File (java.io.File)1