use of com.github.javaparser.resolution.MethodUsage in project javaparser by javaparser.
the class MethodsResolutionLogicTest method compatibilityShouldConsiderAlsoTypeVariablesRaw.
@Test
public void compatibilityShouldConsiderAlsoTypeVariablesRaw() {
JavaParserClassDeclaration constructorDeclaration = (JavaParserClassDeclaration) typeSolver.solveType("com.github.javaparser.ast.body.ConstructorDeclaration");
ResolvedReferenceType rawClassType = (ResolvedReferenceType) ReflectionFactory.typeUsageFor(Class.class, typeSolver);
MethodUsage mu = constructorDeclaration.getAllMethods().stream().filter(m -> m.getDeclaration().getSignature().equals("isThrows(java.lang.Class<? extends java.lang.Throwable>)")).findFirst().get();
assertEquals(true, MethodResolutionLogic.isApplicable(mu, "isThrows", ImmutableList.of(rawClassType), typeSolver));
}
use of com.github.javaparser.resolution.MethodUsage in project javaparser by javaparser.
the class MethodsResolutionTest method solveMethodInInterfaceParent.
@Test
public void solveMethodInInterfaceParent() {
CompilationUnit cu = parseSample("MethodCalls");
ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "MethodCalls");
MethodDeclaration method = Navigator.demandMethod(clazz, "inheritedInterfaceMethod");
MethodCallExpr expression = Navigator.findMethodCall(method, "toString").get();
TypeSolver typeSolver = new ReflectionTypeSolver();
JavaParserFacade javaParserFacade = JavaParserFacade.get(typeSolver);
MethodUsage call1 = javaParserFacade.solveMethodAsUsage(expression);
assertEquals("java.lang.Object.toString()", call1.getQualifiedSignature());
}
use of com.github.javaparser.resolution.MethodUsage in project javaparser by javaparser.
the class MethodsResolutionTest method solveMethodWithClassExpressionAsParameter.
@Test
public void solveMethodWithClassExpressionAsParameter() {
CompilationUnit cu = parseSample("ClassExpression");
com.github.javaparser.ast.body.ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "ClassExpression");
MethodDeclaration method = Navigator.demandMethod(clazz, "foo");
MethodCallExpr expression = Navigator.findMethodCall(method, "noneOf").get();
MethodUsage methodUsage = JavaParserFacade.get(new ReflectionTypeSolver()).solveMethodAsUsage(expression);
assertEquals("noneOf", methodUsage.getName());
}
use of com.github.javaparser.resolution.MethodUsage in project javaparser by javaparser.
the class StatementContextResolutionTest method resolveLocalAndSeveralAnnidatedLevels.
@Test
public void resolveLocalAndSeveralAnnidatedLevels() {
CompilationUnit cu = parseSample("LocalVariableInParent");
com.github.javaparser.ast.body.ClassOrInterfaceDeclaration referencesToField = Navigator.demandClass(cu, "LocalVariableInParent");
MethodDeclaration method = Navigator.demandMethod(referencesToField, "foo4");
MethodCallExpr call = Navigator.findMethodCall(method, "add").get();
TypeSolver typeSolver = new ReflectionTypeSolver();
SymbolReference<? extends ResolvedValueDeclaration> ref = JavaParserFacade.get(typeSolver).solve(call.getScope().get());
assertTrue(ref.isSolved());
assertEquals("java.util.List<Comment>", ref.getCorrespondingDeclaration().getType().describe());
MethodUsage methodUsage = JavaParserFacade.get(typeSolver).solveMethodAsUsage(call);
assertEquals("add", methodUsage.getName());
}
use of com.github.javaparser.resolution.MethodUsage in project javaparser by javaparser.
the class ContextTest method resolveReferenceToOverloadMethodWithNullParam.
@Test
public void resolveReferenceToOverloadMethodWithNullParam() {
CompilationUnit cu = parseSample("OverloadedMethods");
com.github.javaparser.ast.body.ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "OverloadedMethods");
MethodDeclaration method = Navigator.demandMethod(clazz, "m1");
MethodCallExpr call = Navigator.findMethodCall(method, "overloaded").get();
ReflectionTypeSolver typeSolver = new ReflectionTypeSolver();
MethodUsage ref = JavaParserFacade.get(typeSolver).solveMethodAsUsage(call);
assertEquals("overloaded", ref.getName());
assertEquals(1, ref.getNoParams());
assertEquals("java.lang.String", ref.getParamTypes().get(0).describe());
}
Aggregations