use of com.github.javaparser.resolution.MethodUsage in project javaparser by javaparser.
the class JavaParserAnonymousClassDeclarationTest method callingAnonymousClassInnerMethod.
@Test
public void callingAnonymousClassInnerMethod() {
CompilationUnit cu = parseSample("AnonymousClassDeclarations");
ClassOrInterfaceDeclaration aClass = Navigator.demandClass(cu, "AnonymousClassDeclarations");
MethodDeclaration method = Navigator.demandMethod(aClass, "fooBar3");
MethodCallExpr methodCall = Navigator.findMethodCall(method, "callAnnonClassInnerMethod").get();
CombinedTypeSolver combinedTypeSolver = new CombinedTypeSolver();
combinedTypeSolver.add(new ReflectionTypeSolver());
MethodUsage methodUsage = JavaParserFacade.get(combinedTypeSolver).solveMethodAsUsage(methodCall);
assertTrue(methodUsage.getQualifiedSignature().startsWith("AnonymousClassDeclarations"));
assertTrue(methodUsage.getQualifiedSignature().contains("Anonymous-"));
assertTrue(methodUsage.getQualifiedSignature().endsWith("callAnnonClassInnerMethod()"));
}
use of com.github.javaparser.resolution.MethodUsage in project javaparser by javaparser.
the class JavaParserAnonymousClassDeclarationTest method anonymousClassAsMethodArgument.
@Test
public void anonymousClassAsMethodArgument() {
CompilationUnit cu = parseSample("AnonymousClassDeclarations");
ClassOrInterfaceDeclaration aClass = Navigator.demandClass(cu, "AnonymousClassDeclarations");
MethodDeclaration method = Navigator.demandMethod(aClass, "fooBar1");
MethodCallExpr methodCall = Navigator.findMethodCall(method, "of").get();
CombinedTypeSolver combinedTypeSolver = new CombinedTypeSolver();
combinedTypeSolver.add(new ReflectionTypeSolver());
MethodUsage methodUsage = JavaParserFacade.get(combinedTypeSolver).solveMethodAsUsage(methodCall);
assertThat(methodUsage.getQualifiedSignature(), is("AnonymousClassDeclarations.ParDo.of(AnonymousClassDeclarations.DoFn<I, O>)"));
}
use of com.github.javaparser.resolution.MethodUsage in project javaparser by javaparser.
the class JavaParserAnonymousClassDeclarationTest method usingAnonymousSuperClassInnerType.
@Test
public void usingAnonymousSuperClassInnerType() {
CompilationUnit cu = parseSample("AnonymousClassDeclarations");
ClassOrInterfaceDeclaration aClass = Navigator.demandClass(cu, "AnonymousClassDeclarations");
MethodDeclaration method = Navigator.demandMethod(aClass, "fooBar4");
MethodCallExpr methodCall = Navigator.findMethodCall(method, "toString").get();
CombinedTypeSolver combinedTypeSolver = new CombinedTypeSolver();
combinedTypeSolver.add(new ReflectionTypeSolver());
MethodUsage methodUsage = JavaParserFacade.get(combinedTypeSolver).solveMethodAsUsage(methodCall);
assertThat(methodUsage.getQualifiedSignature(), is("java.lang.Enum.toString()"));
}
use of com.github.javaparser.resolution.MethodUsage in project javaparser by javaparser.
the class JavaParserAnonymousClassDeclarationTest method usingAnonymousClassInnerType.
@Test
public void usingAnonymousClassInnerType() {
CompilationUnit cu = parseSample("AnonymousClassDeclarations");
ClassOrInterfaceDeclaration aClass = Navigator.demandClass(cu, "AnonymousClassDeclarations");
MethodDeclaration method = Navigator.demandMethod(aClass, "fooBar5");
MethodCallExpr methodCall = Navigator.findMethodCall(method, "toString").get();
CombinedTypeSolver combinedTypeSolver = new CombinedTypeSolver();
combinedTypeSolver.add(new ReflectionTypeSolver());
MethodUsage methodUsage = JavaParserFacade.get(combinedTypeSolver).solveMethodAsUsage(methodCall);
assertThat(methodUsage.getQualifiedSignature(), is("java.lang.Enum.toString()"));
}
use of com.github.javaparser.resolution.MethodUsage in project javaparser by javaparser.
the class JavaParserFacadeResolutionTest method solvingReferenceToUnsupportedOperationException.
// See issue 42
@Test
public void solvingReferenceToUnsupportedOperationException() {
String code = "public class Bla {\n" + " public void main()\n" + " {\n" + " try\n" + " {\n" + " int i = 0;\n" + " }\n" + " catch (UnsupportedOperationException e)\n" + " {\n" + " String s;\n" + " e.getMessage();\n" + " }\n" + " }\n" + "}";
MethodCallExpr methodCallExpr = Navigator.findNodeOfGivenClass(JavaParser.parse(code), MethodCallExpr.class);
MethodUsage methodUsage = JavaParserFacade.get(new ReflectionTypeSolver()).solveMethodAsUsage(methodCallExpr);
assertEquals("java.lang.Throwable.getMessage()", methodUsage.getQualifiedSignature());
}
Aggregations