Search in sources :

Example 1 with JavaParserAnonymousClassDeclaration

use of com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserAnonymousClassDeclaration in project javaparser by javaparser.

the class MethodsResolutionTest method thisInAnonymousClass.

@Test
public void thisInAnonymousClass() {
    CompilationUnit cu = parseSample("ThisInAnonymousClass");
    ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "Bar");
    ThisExpr thisExpression = Navigator.findNodeOfGivenClass(clazz, ThisExpr.class);
    ResolvedType type = JavaParserFacade.get(new ReflectionTypeSolver()).getType(thisExpression);
    assertEquals(true, type.isReferenceType());
    assertEquals(true, type.asReferenceType().getTypeDeclaration() instanceof JavaParserAnonymousClassDeclaration);
}
Also used : CompilationUnit(com.github.javaparser.ast.CompilationUnit) ClassOrInterfaceDeclaration(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration) JavaParserAnonymousClassDeclaration(com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserAnonymousClassDeclaration) ReflectionTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver) ThisExpr(com.github.javaparser.ast.expr.ThisExpr) ResolvedType(com.github.javaparser.resolution.types.ResolvedType) Test(org.junit.Test)

Aggregations

CompilationUnit (com.github.javaparser.ast.CompilationUnit)1 ClassOrInterfaceDeclaration (com.github.javaparser.ast.body.ClassOrInterfaceDeclaration)1 ThisExpr (com.github.javaparser.ast.expr.ThisExpr)1 ResolvedType (com.github.javaparser.resolution.types.ResolvedType)1 JavaParserAnonymousClassDeclaration (com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserAnonymousClassDeclaration)1 ReflectionTypeSolver (com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver)1 Test (org.junit.Test)1