use of com.github.javaparser.resolution.MethodUsage in project javaparser by javaparser.
the class ContextTest method resolveReferenceToLambdaParamSimplified.
@Test
public void resolveReferenceToLambdaParamSimplified() {
CompilationUnit cu = parseSample("NavigatorSimplified");
com.github.javaparser.ast.body.ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "Navigator");
MethodDeclaration method = Navigator.demandMethod(clazz, "findType");
MethodCallExpr call = Navigator.findMethodCall(method, "isEmpty").get();
TypeSolver typeSolver = new ReflectionTypeSolver();
SymbolSolver symbolSolver = new SymbolSolver(typeSolver);
MethodUsage ref = symbolSolver.solveMethod("isEmpty", Collections.emptyList(), call);
assertEquals("isEmpty", ref.getName());
assertEquals("java.lang.String", ref.declaringType().getQualifiedName());
}
use of com.github.javaparser.resolution.MethodUsage 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.resolution.MethodUsage 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.resolution.MethodUsage 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.resolution.MethodUsage 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());
}
Aggregations