use of com.github.javaparser.ast.expr.MethodCallExpr in project javaparser by javaparser.
the class ContextTest method resolveTypeUsageOfMethodInGenericClass.
@Test
public void resolveTypeUsageOfMethodInGenericClass() 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 callToStream = Navigator.findMethodCall(method, "stream").get();
String pathToJar = adaptPath("src/test/resources/javaparser-core-2.1.0.jar");
TypeSolver typeSolver = new CombinedTypeSolver(new ReflectionTypeSolver(), new JarTypeSolver(pathToJar));
MethodUsage filterUsage = JavaParserFacade.get(typeSolver).solveMethodAsUsage(callToStream);
assertEquals("java.util.stream.Stream<com.github.javaparser.ast.body.TypeDeclaration>", filterUsage.returnType().describe());
}
use of com.github.javaparser.ast.expr.MethodCallExpr in project javaparser by javaparser.
the class ContextTest method resolveReferenceToCallOnLambdaParam.
@Test
public void resolveReferenceToCallOnLambdaParam() 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 callToGetName = Navigator.findMethodCall(method, "getName").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(callToGetName);
assertEquals("getName", methodUsage.getName());
assertEquals("com.github.javaparser.ast.body.TypeDeclaration", methodUsage.declaringType().getQualifiedName());
}
use of com.github.javaparser.ast.expr.MethodCallExpr in project javaparser by javaparser.
the class EnumResolutionTest method enumAndStaticInitializer.
@Test
public void enumAndStaticInitializer() {
CompilationUnit cu = parseSample("EnumAndStaticInitializer");
com.github.javaparser.ast.body.ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "MyClass");
MethodCallExpr call = Navigator.findMethodCall(clazz, "put").get();
ResolvedType ref = JavaParserFacade.get(new ReflectionTypeSolver()).getType(call);
assertEquals("MyClass.Primitive", ref.describe());
}
use of com.github.javaparser.ast.expr.MethodCallExpr in project javaparser by javaparser.
the class GenericsResolutionTest method methodWithGenericParameterTypes.
@Test
public void methodWithGenericParameterTypes() {
CompilationUnit cu = parseSample("GenericCollectionWithExtension");
ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "Foo");
MethodDeclaration method = Navigator.demandMethod(clazz, "bar");
MethodCallExpr methodCall = Navigator.findMethodCall(method, "foo").get();
TypeSolver typeSolver = new ReflectionTypeSolver();
JavaParserFacade javaParserFacade = JavaParserFacade.get(typeSolver);
MethodUsage methodUsage = javaParserFacade.solveMethodAsUsage(methodCall);
assertEquals("foo", methodUsage.getName());
}
use of com.github.javaparser.ast.expr.MethodCallExpr in project javaparser by javaparser.
the class GenericsResolutionTest method genericsInheritance.
@Test
public void genericsInheritance() {
CompilationUnit cu = parseSample("MethodTypeParams");
ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "VoidVisitorAdapter");
MethodDeclaration method = Navigator.demandMethod(clazz, "visit");
MethodCallExpr call = Navigator.findMethodCall(method, "accept").get();
Expression thisRef = call.getArguments().get(0);
TypeSolver typeSolver = new ReflectionTypeSolver();
JavaParserFacade javaParserFacade = JavaParserFacade.get(typeSolver);
ResolvedType voidVisitorAdapterOfA = javaParserFacade.getType(thisRef);
List<ResolvedReferenceType> allAncestors = voidVisitorAdapterOfA.asReferenceType().getAllAncestors();
assertEquals(2, allAncestors.size());
}
Aggregations