use of com.github.javaparser.ast.body.MethodDeclaration in project javaparser by javaparser.
the class GenericsResolutionTest method typeParamOnReturnTypeStep1.
@Test
public void typeParamOnReturnTypeStep1() {
CompilationUnit cu = parseSample("TypeParamOnReturnType");
ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "TypeParamOnReturnType");
MethodDeclaration method = Navigator.demandMethod(clazz, "nodeEquals");
ThisExpr thisExpr = Navigator.findNodeOfGivenClass(method, ThisExpr.class);
ResolvedType type = JavaParserFacade.get(new ReflectionTypeSolver()).getType(thisExpr);
assertEquals(false, type.isTypeVariable());
assertEquals("TypeParamOnReturnType", type.describe());
}
use of com.github.javaparser.ast.body.MethodDeclaration in project javaparser by javaparser.
the class GenericsResolutionTest method typeParamOnReturnTypeStep2.
@Test
public void typeParamOnReturnTypeStep2() {
CompilationUnit cu = parseSample("TypeParamOnReturnType");
ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "TypeParamOnReturnType");
MethodDeclaration method = Navigator.demandMethod(clazz, "nodeEquals");
NameExpr n1 = Navigator.findNameExpression(method, "n1").get();
ResolvedType type = JavaParserFacade.get(new ReflectionTypeSolver()).getType(n1);
assertEquals(true, type.isTypeVariable());
assertEquals("T", type.describe());
}
use of com.github.javaparser.ast.body.MethodDeclaration 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.ast.body.MethodDeclaration in project javaparser by javaparser.
the class VariadicResolutionTest method issue7.
@Test
public void issue7() {
CompilationUnit cu = parseSample("Generics_issue7");
ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "SomeCollection");
MethodDeclaration method = Navigator.demandMethod(clazz, "foo3");
ReturnStmt stmt = (ReturnStmt) method.getBody().get().getStatements().get(0);
Expression expression = stmt.getExpression().get();
JavaParserFacade javaParserFacade = JavaParserFacade.get(new ReflectionTypeSolver());
ResolvedType type = javaParserFacade.getType(expression);
assertEquals(true, type.isReferenceType());
assertEquals(List.class.getCanonicalName(), type.asReferenceType().getQualifiedName());
assertEquals("java.util.List<java.lang.Long>", type.describe());
}
use of com.github.javaparser.ast.body.MethodDeclaration 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