use of com.github.javaparser.resolution.MethodUsage in project javaparser by javaparser.
the class VariadicResolutionTest method methodCallWithReferenceTypeAsVaridicArgumentIsSolved.
@Test
public void methodCallWithReferenceTypeAsVaridicArgumentIsSolved() {
CompilationUnit cu = parseSample("MethodCalls");
ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "MethodCalls");
MethodDeclaration method = Navigator.demandMethod(clazz, "variadicMethod");
MethodCallExpr callExpr = Navigator.findMethodCall(method, "variadicMethod").get();
TypeSolver typeSolver = new ReflectionTypeSolver();
JavaParserFacade javaParserFacade = JavaParserFacade.get(typeSolver);
MethodUsage callee = javaParserFacade.solveMethodAsUsage(callExpr);
assertEquals("variadicMethod", callee.getName());
}
use of com.github.javaparser.resolution.MethodUsage in project javaparser by javaparser.
the class ClassOrInterfaceDeclarationContextResolutionTest method solveMethodAsUsageInheritedCase.
@Test
public void solveMethodAsUsageInheritedCase() {
CompilationUnit cu = parseSample("ClassWithMethods");
ClassOrInterfaceDeclaration classOrInterfaceDeclaration = Navigator.demandClass(cu, "A");
Context context = new ClassOrInterfaceDeclarationContext(classOrInterfaceDeclaration, typeSolver);
Optional<MethodUsage> ref = context.solveMethodAsUsage("foo2", ImmutableList.of(), new ReflectionTypeSolver());
assertEquals(true, ref.isPresent());
assertEquals("Super", ref.get().declaringType().getName());
assertEquals(0, ref.get().getNoParams());
}
use of com.github.javaparser.resolution.MethodUsage in project javaparser by javaparser.
the class ClassOrInterfaceDeclarationContextResolutionTest method solveMethodAsUsageOverrideCase.
@Test
public void solveMethodAsUsageOverrideCase() {
CompilationUnit cu = parseSample("ClassWithMethods");
ClassOrInterfaceDeclaration classOrInterfaceDeclaration = Navigator.demandClass(cu, "A");
Context context = new ClassOrInterfaceDeclarationContext(classOrInterfaceDeclaration, typeSolver);
Optional<MethodUsage> ref = context.solveMethodAsUsage("foo1", ImmutableList.of(), new ReflectionTypeSolver());
assertEquals(true, ref.isPresent());
assertEquals("A", ref.get().declaringType().getName());
assertEquals(0, ref.get().getNoParams());
}
use of com.github.javaparser.resolution.MethodUsage in project javaparser by javaparser.
the class ClassOrInterfaceDeclarationContextResolutionTest method solveMethodAsUsageWithPrimitiveParameters.
@Test
public void solveMethodAsUsageWithPrimitiveParameters() {
CompilationUnit cu = parseSample("ClassWithMethods");
ClassOrInterfaceDeclaration classOrInterfaceDeclaration = Navigator.demandClass(cu, "A");
Context context = new ClassOrInterfaceDeclarationContext(classOrInterfaceDeclaration, typeSolver);
ResolvedType intType = ResolvedPrimitiveType.INT;
Optional<MethodUsage> ref = context.solveMethodAsUsage("foo3", ImmutableList.of(intType), new ReflectionTypeSolver());
assertEquals(true, ref.isPresent());
assertEquals("A", ref.get().declaringType().getName());
assertEquals(1, ref.get().getNoParams());
}
use of com.github.javaparser.resolution.MethodUsage in project javaparser by javaparser.
the class ClassOrInterfaceDeclarationContextResolutionTest method solveMethodAsUsageWithAmbiguosCall.
@Test(expected = MethodAmbiguityException.class)
public void solveMethodAsUsageWithAmbiguosCall() {
CompilationUnit cu = parseSample("ClassWithMethods");
ClassOrInterfaceDeclaration classOrInterfaceDeclaration = Navigator.demandClass(cu, "A");
Context context = new ClassOrInterfaceDeclarationContext(classOrInterfaceDeclaration, typeSolver);
Optional<MethodUsage> ref = context.solveMethodAsUsage("foo5", ImmutableList.of(NullType.INSTANCE), new ReflectionTypeSolver());
}
Aggregations