use of com.github.javaparser.symbolsolver.model.resolution.TypeSolver in project javaparser by javaparser.
the class GenericsResolutionTest method genericCollectionWithWildcards.
@Test
public void genericCollectionWithWildcards() {
CompilationUnit cu = parseSample("GenericCollection");
ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "Foo");
MethodDeclaration method = Navigator.demandMethod(clazz, "bar");
ReturnStmt returnStmt = Navigator.findReturnStmt(method);
TypeSolver typeSolver = new ReflectionTypeSolver();
Expression returnStmtExpr = returnStmt.getExpression().get();
JavaParserFacade javaParserFacade = JavaParserFacade.get(typeSolver);
ResolvedType type = javaParserFacade.getType(returnStmtExpr);
assertEquals(false, type.isTypeVariable());
assertEquals("boolean", type.describe());
}
use of com.github.javaparser.symbolsolver.model.resolution.TypeSolver in project javaparser by javaparser.
the class GenericsResolutionTest method classCastScope.
@Test
public void classCastScope() {
CompilationUnit cu = parseSample("ClassCast");
ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "ClassCast");
MethodDeclaration method = Navigator.demandMethod(clazz, "getNodesByType");
MethodCallExpr call = Navigator.findMethodCall(method, "cast").get();
TypeSolver typeSolver = new ReflectionTypeSolver();
Expression scope = call.getScope().get();
ResolvedType type = JavaParserFacade.get(typeSolver).getType(scope);
// System.out.println(typeUsage);
assertEquals(false, type.isTypeVariable());
assertEquals("java.lang.Class<N>", type.describe());
}
use of com.github.javaparser.symbolsolver.model.resolution.TypeSolver in project javaparser by javaparser.
the class ReflectionMethodDeclarationTest method testGetSignature.
@Test
public void testGetSignature() {
TypeSolver typeResolver = new ReflectionTypeSolver();
ResolvedClassDeclaration object = new ReflectionClassDeclaration(Object.class, typeResolver);
ResolvedInterfaceDeclaration list = new ReflectionInterfaceDeclaration(List.class, typeResolver);
ResolvedMethodDeclaration hashCode = object.getAllMethods().stream().filter(m -> m.getName().equals("hashCode")).findFirst().get().getDeclaration();
ResolvedMethodDeclaration equals = object.getAllMethods().stream().filter(m -> m.getName().equals("equals")).findFirst().get().getDeclaration();
ResolvedMethodDeclaration containsAll = list.getAllMethods().stream().filter(m -> m.getName().equals("containsAll")).findFirst().get().getDeclaration();
ResolvedMethodDeclaration subList = list.getAllMethods().stream().filter(m -> m.getName().equals("subList")).findFirst().get().getDeclaration();
assertEquals("hashCode()", hashCode.getSignature());
assertEquals("equals(java.lang.Object)", equals.getSignature());
assertEquals("containsAll(java.util.Collection<? extends java.lang.Object>)", containsAll.getSignature());
assertEquals("subList(int, int)", subList.getSignature());
}
use of com.github.javaparser.symbolsolver.model.resolution.TypeSolver in project javaparser by javaparser.
the class VariadicResolutionTest method resolveVariadicMethodWithGenericArgument.
@Test
public void resolveVariadicMethodWithGenericArgument() {
CompilationUnit cu = parseSample("MethodCalls");
ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "MethodCalls");
MethodDeclaration method = Navigator.demandMethod(clazz, "genericMethodTest");
MethodCallExpr callExpr = Navigator.findMethodCall(method, "variadicWithGenericArg").get();
TypeSolver typeSolver = new ReflectionTypeSolver();
JavaParserFacade javaParserFacade = JavaParserFacade.get(typeSolver);
MethodUsage callee = javaParserFacade.solveMethodAsUsage(callExpr);
assertEquals("variadicWithGenericArg", callee.getName());
}
use of com.github.javaparser.symbolsolver.model.resolution.TypeSolver 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");
}
Aggregations