use of com.github.javaparser.symbolsolver.model.resolution.TypeSolver in project javaparser by javaparser.
the class StatementContextResolutionTest method resolveMethodOnGenericClass.
@Test
public void resolveMethodOnGenericClass() {
CompilationUnit cu = parseSample("LocalVariableInParent");
com.github.javaparser.ast.body.ClassOrInterfaceDeclaration referencesToField = Navigator.demandClass(cu, "LocalVariableInParent");
MethodDeclaration method = Navigator.demandMethod(referencesToField, "foo5");
MethodCallExpr call = Navigator.findMethodCall(method, "add").get();
TypeSolver typeSolver = new ReflectionTypeSolver();
SymbolReference<? extends ResolvedValueDeclaration> ref = JavaParserFacade.get(typeSolver).solve(call.getScope().get());
assertTrue(ref.isSolved());
assertEquals("java.util.List<Comment>", ref.getCorrespondingDeclaration().getType().describe());
MethodUsage methodUsage = JavaParserFacade.get(typeSolver).solveMethodAsUsage(call);
assertEquals("add", methodUsage.getName());
}
use of com.github.javaparser.symbolsolver.model.resolution.TypeSolver in project javaparser by javaparser.
the class JavaParserTypeParameterResolutionTest method declaredOnMethodPositiveCase.
@Test
public void declaredOnMethodPositiveCase() {
CompilationUnit cu = parseSample("MethodTypeParameter");
TypeSolver typeSolver = new ReflectionTypeSolver();
JavaParserFacade javaParserFacade = JavaParserFacade.get(typeSolver);
ClassOrInterfaceDeclaration classDecl = Navigator.demandClass(cu, "Foo");
MethodDeclaration methodDecl = Navigator.demandMethod(classDecl, "usage");
MethodCallExpr callToFoo = (MethodCallExpr) Navigator.findReturnStmt(methodDecl).getExpression().get();
ResolvedMethodDeclaration methodDeclaration = javaParserFacade.solve(callToFoo).getCorrespondingDeclaration();
for (ResolvedTypeParameterDeclaration tp : methodDeclaration.getTypeParameters()) {
assertTrue(tp instanceof JavaParserTypeParameter);
assertEquals("C", tp.getName());
assertEquals(true, tp.declaredOnMethod());
assertEquals(false, tp.declaredOnType());
}
}
use of com.github.javaparser.symbolsolver.model.resolution.TypeSolver in project javaparser by javaparser.
the class SymbolResolutionResolutionTest method conditionalExpressionExample.
@Test
public void conditionalExpressionExample() {
CompilationUnit cu = parseSample("JreConditionalExpression");
ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "MyClass");
MethodDeclaration method = Navigator.demandMethod(clazz, "foo1");
ReturnStmt returnStmt = Navigator.findReturnStmt(method);
Expression expression = returnStmt.getExpression().get();
TypeSolver typeSolver = new ReflectionTypeSolver();
ResolvedType ref = JavaParserFacade.get(typeSolver).getType(expression);
assertEquals("java.lang.String", ref.describe());
}
use of com.github.javaparser.symbolsolver.model.resolution.TypeSolver in project javaparser by javaparser.
the class SymbolResolutionResolutionTest method getTypeOfFieldAccess.
@Test
public void getTypeOfFieldAccess() {
CompilationUnit cu = parseSample("ReflectionFieldOfItself");
ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "MyClass");
VariableDeclarator field = Navigator.demandField(clazz, "PUBLIC");
TypeSolver typeSolver = new ReflectionTypeSolver();
ResolvedType ref = JavaParserFacade.get(typeSolver).getType(field.getInitializer().get());
assertEquals("int", ref.describe());
}
use of com.github.javaparser.symbolsolver.model.resolution.TypeSolver in project javaparser by javaparser.
the class SymbolResolutionResolutionTest method getTypeOfField.
@Test
public void getTypeOfField() {
CompilationUnit cu = parseSample("ReflectionFieldOfItself");
ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "MyClass");
VariableDeclarator field = Navigator.demandField(clazz, "PUBLIC");
TypeSolver typeSolver = new ReflectionTypeSolver();
ResolvedType ref = JavaParserFacade.get(typeSolver).getType(field);
assertEquals("int", ref.describe());
}
Aggregations