use of com.github.javaparser.ast.expr.MethodCallExpr in project javaparser by javaparser.
the class GenericsResolutionTest method typeParamOnReturnTypeStep3.
@Test
public void typeParamOnReturnTypeStep3() {
CompilationUnit cu = parseSample("TypeParamOnReturnType");
ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "TypeParamOnReturnType");
MethodDeclaration method = Navigator.demandMethod(clazz, "nodeEquals");
MethodCallExpr call = Navigator.findMethodCall(method, "accept").get();
JavaParserFacade javaParserFacade = JavaParserFacade.get(new ReflectionTypeSolver());
ResolvedType type = javaParserFacade.getType(call);
assertEquals(false, type.isTypeVariable());
assertEquals("java.lang.Boolean", type.describe());
}
use of com.github.javaparser.ast.expr.MethodCallExpr 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.ast.expr.MethodCallExpr 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.expr.MethodCallExpr 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.ast.expr.MethodCallExpr in project javaparser by javaparser.
the class JavaParserFacadeResolutionTest method solveTryWithResourceVariable.
// See issue 119
@Test
public void solveTryWithResourceVariable() {
String code = "import java.util.Scanner; class A { void foo() { try (Scanner sc = new Scanner(System.in)) {\n" + " sc.nextLine();\n" + "} } }";
CompilationUnit cu = JavaParser.parse(code);
MethodCallExpr methodCallExpr = Navigator.findMethodCall(cu, "nextLine").get();
Expression scope = methodCallExpr.getScope().get();
ResolvedType type = JavaParserFacade.get(new ReflectionTypeSolver()).getType(scope);
assertEquals(true, type.isReferenceType());
assertEquals("java.util.Scanner", type.asReferenceType().getQualifiedName());
}
Aggregations