use of com.github.javaparser.ast.expr.MethodCallExpr in project javaparser by javaparser.
the class ContextTest method resolveReferenceToOverloadMethodWithNullParam.
@Test
public void resolveReferenceToOverloadMethodWithNullParam() {
CompilationUnit cu = parseSample("OverloadedMethods");
com.github.javaparser.ast.body.ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "OverloadedMethods");
MethodDeclaration method = Navigator.demandMethod(clazz, "m1");
MethodCallExpr call = Navigator.findMethodCall(method, "overloaded").get();
ReflectionTypeSolver typeSolver = new ReflectionTypeSolver();
MethodUsage ref = JavaParserFacade.get(typeSolver).solveMethodAsUsage(call);
assertEquals("overloaded", ref.getName());
assertEquals(1, ref.getNoParams());
assertEquals("java.lang.String", ref.getParamTypes().get(0).describe());
}
use of com.github.javaparser.ast.expr.MethodCallExpr in project javaparser by javaparser.
the class ContextTest method resolveGenericReturnTypeOfMethodInJar.
@Test
public void resolveGenericReturnTypeOfMethodInJar() throws ParseException, IOException {
CompilationUnit cu = parseSample("Navigator");
com.github.javaparser.ast.body.ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "Navigator");
MethodDeclaration method = Navigator.demandMethod(clazz, "findType");
MethodCallExpr call = Navigator.findMethodCall(method, "getTypes").get();
String pathToJar = adaptPath("src/test/resources/javaparser-core-2.1.0.jar");
TypeSolver typeSolver = new CombinedTypeSolver(new ReflectionTypeSolver(), new JarTypeSolver(pathToJar));
MethodUsage methodUsage = JavaParserFacade.get(typeSolver).solveMethodAsUsage(call);
assertEquals("getTypes", methodUsage.getName());
assertEquals("java.util.List<com.github.javaparser.ast.body.TypeDeclaration>", methodUsage.returnType().describe());
assertEquals(1, methodUsage.returnType().asReferenceType().typeParametersValues().size());
assertEquals("com.github.javaparser.ast.body.TypeDeclaration", methodUsage.returnType().asReferenceType().typeParametersValues().get(0).describe());
}
use of com.github.javaparser.ast.expr.MethodCallExpr in project javaparser by javaparser.
the class GenericsResolutionTest method methodTypeParams.
@Test
public void methodTypeParams() {
CompilationUnit cu = parseSample("MethodTypeParams");
ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "VoidVisitorAdapter");
MethodDeclaration method = Navigator.demandMethod(clazz, "visit");
MethodCallExpr call = Navigator.findMethodCall(method, "accept").get();
ResolvedType type = JavaParserFacade.get(new ReflectionTypeSolver()).getType(call);
assertEquals(false, type.isTypeVariable());
assertEquals("void", type.describe());
}
use of com.github.javaparser.ast.expr.MethodCallExpr in project javaparser by javaparser.
the class GenericsResolutionTest method resolveUsageOfMethodOfGenericClass.
@Test
public void resolveUsageOfMethodOfGenericClass() {
CompilationUnit cu = parseSample("Generics");
ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "GenericMethodCalls.Derived");
MethodDeclaration method = Navigator.demandMethod(clazz, "caller");
MethodCallExpr expression = Navigator.findMethodCall(method, "callee").get();
MethodUsage methodUsage = JavaParserFacade.get(new ReflectionTypeSolver()).solveMethodAsUsage(expression);
assertEquals("callee", methodUsage.getName());
}
use of com.github.javaparser.ast.expr.MethodCallExpr in project javaparser by javaparser.
the class LambdaExprContextResolutionTest method solveParameterOfLambdaInMethodCallExpr.
@Test
public void solveParameterOfLambdaInMethodCallExpr() {
CompilationUnit cu = parseSample("Lambda");
com.github.javaparser.ast.body.ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "Agenda");
MethodDeclaration method = Navigator.demandMethod(clazz, "lambdaMap");
ReturnStmt returnStmt = Navigator.findReturnStmt(method);
MethodCallExpr methodCallExpr = (MethodCallExpr) returnStmt.getExpression().get();
LambdaExpr lambdaExpr = (LambdaExpr) methodCallExpr.getArguments().get(0);
Context context = new LambdaExprContext(lambdaExpr, typeSolver);
Optional<Value> ref = context.solveSymbolAsValue("p", typeSolver);
assertTrue(ref.isPresent());
assertEquals("? super java.lang.String", ref.get().getType().describe());
}
Aggregations