use of com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver in project javaparser by javaparser.
the class FieldAccessContextResolutionTest method solveMethodCallInFieldAccessContext.
@Test
public void solveMethodCallInFieldAccessContext() {
CompilationUnit cu = parseSample("MethodCalls");
com.github.javaparser.ast.body.ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "MethodCalls");
MethodDeclaration method = Navigator.demandMethod(clazz, "bar2");
MethodCallExpr methodCallExpr = Navigator.findMethodCall(method, "getSelf").get();
TypeSolver typeSolver = new ReflectionTypeSolver();
MethodUsage methodUsage = JavaParserFacade.get(typeSolver).solveMethodAsUsage(methodCallExpr);
assertEquals(methodUsage.getName(), "getSelf");
}
use of com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver in project javaparser by javaparser.
the class FieldsResolutionTest method accessClassFieldThroughThis.
@Test
public void accessClassFieldThroughThis() {
CompilationUnit cu = parseSample("AccessClassMemberThroughThis");
com.github.javaparser.ast.body.ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "AccessClassMemberThroughThis");
MethodDeclaration method = Navigator.demandMethod(clazz, "getLabel2");
ReturnStmt returnStmt = (ReturnStmt) method.getBody().get().getStatements().get(0);
Expression expression = returnStmt.getExpression().get();
ResolvedType ref = JavaParserFacade.get(new ReflectionTypeSolver()).getType(expression);
assertEquals("java.lang.String", ref.describe());
}
use of com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver in project javaparser by javaparser.
the class FieldsResolutionTest method accessEnumMethodThroughThis.
@Test
public void accessEnumMethodThroughThis() {
CompilationUnit cu = parseSample("AccessEnumMemberThroughThis");
com.github.javaparser.ast.body.EnumDeclaration enumDecl = Navigator.demandEnum(cu, "AccessEnumMemberThroughThis");
MethodDeclaration method = Navigator.demandMethod(enumDecl, "getLabel2");
ReturnStmt returnStmt = (ReturnStmt) method.getBody().get().getStatements().get(0);
Expression expression = returnStmt.getExpression().get();
ResolvedType ref = JavaParserFacade.get(new ReflectionTypeSolver()).getType(expression);
assertEquals("java.lang.String", ref.describe());
}
use of com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver in project javaparser by javaparser.
the class FieldsResolutionTest method accessEnumFieldThroughThis.
@Test
public void accessEnumFieldThroughThis() {
CompilationUnit cu = parseSample("AccessEnumMemberThroughThis");
com.github.javaparser.ast.body.EnumDeclaration enumDecl = Navigator.demandEnum(cu, "AccessEnumMemberThroughThis");
MethodDeclaration method = Navigator.demandMethod(enumDecl, "getLabel");
SimpleName expression = Navigator.findSimpleName(method, "label").get();
SymbolReference ref = JavaParserFacade.get(new ReflectionTypeSolver()).solve(expression);
assertTrue(ref.isSolved());
assertEquals("label", ref.getCorrespondingDeclaration().getName());
}
use of com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver in project javaparser by javaparser.
the class FieldsResolutionTest method accessFieldThroughSuper.
@Test
public void accessFieldThroughSuper() {
CompilationUnit cu = parseSample("AccessThroughSuper");
com.github.javaparser.ast.body.ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "AccessThroughSuper.SubClass");
MethodDeclaration method = Navigator.demandMethod(clazz, "fieldTest");
ReturnStmt returnStmt = (ReturnStmt) method.getBody().get().getStatements().get(0);
Expression expression = returnStmt.getExpression().get();
ResolvedType ref = JavaParserFacade.get(new ReflectionTypeSolver()).getType(expression);
assertEquals("java.lang.String", ref.describe());
}
Aggregations