use of com.github.javaparser.ast.expr.MethodCallExpr 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.ast.expr.MethodCallExpr in project javaparser by javaparser.
the class MethodsResolutionTest method solveMethodWithTypePromotionsToByteWithExtraParam.
@Test
public void solveMethodWithTypePromotionsToByteWithExtraParam() {
CompilationUnit cu = parseSample("Issue338");
ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "TypePromotionsWithExtraParam");
MethodDeclaration method = Navigator.demandMethod(clazz, "callingByte");
{
MethodCallExpr expression = method.getBody().get().getStatements().get(0).asExpressionStmt().getExpression().asMethodCallExpr();
SymbolReference<ResolvedMethodDeclaration> reference = JavaParserFacade.get(new ReflectionTypeSolver()).solve(expression);
assertEquals(true, reference.isSolved());
assertEquals("byteParam", reference.getCorrespondingDeclaration().getName());
}
{
MethodCallExpr expression = method.getBody().get().getStatements().get(1).asExpressionStmt().getExpression().asMethodCallExpr();
SymbolReference<ResolvedMethodDeclaration> reference = JavaParserFacade.get(new ReflectionTypeSolver()).solve(expression);
assertEquals(false, reference.isSolved());
}
{
MethodCallExpr expression = method.getBody().get().getStatements().get(2).asExpressionStmt().getExpression().asMethodCallExpr();
SymbolReference<ResolvedMethodDeclaration> reference = JavaParserFacade.get(new ReflectionTypeSolver()).solve(expression);
assertEquals(false, reference.isSolved());
}
{
MethodCallExpr expression = method.getBody().get().getStatements().get(3).asExpressionStmt().getExpression().asMethodCallExpr();
SymbolReference<ResolvedMethodDeclaration> reference = JavaParserFacade.get(new ReflectionTypeSolver()).solve(expression);
assertEquals(false, reference.isSolved());
}
}
use of com.github.javaparser.ast.expr.MethodCallExpr 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.ast.expr.MethodCallExpr 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.ast.expr.MethodCallExpr in project javaparser by javaparser.
the class ContextTest method resolveReferenceToMethodWithLambda.
@Test
public void resolveReferenceToMethodWithLambda() {
CompilationUnit cu = parseSample("NavigatorSimplified");
com.github.javaparser.ast.body.ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "Navigator");
MethodDeclaration method = Navigator.demandMethod(clazz, "findType");
MethodCallExpr methodCallExpr = Navigator.findMethodCall(method, "filter").get();
TypeSolver typeSolver = new ReflectionTypeSolver();
ResolvedType ref = JavaParserFacade.get(typeSolver).getType(methodCallExpr);
assertEquals("java.util.stream.Stream<java.lang.String>", ref.describe());
assertEquals(1, ref.asReferenceType().typeParametersValues().size());
assertEquals("java.lang.String", ref.asReferenceType().typeParametersValues().get(0).describe());
}
Aggregations