use of com.github.javaparser.ast.expr.MethodCallExpr 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.ast.expr.MethodCallExpr in project javaparser by javaparser.
the class JavaParserFacadeResolutionTest method solvingReferenceToCatchClauseParam.
// See issue 46
@Test
public void solvingReferenceToCatchClauseParam() {
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);
NameExpr nameE = (NameExpr) methodCallExpr.getScope().get();
SymbolReference<? extends ResolvedValueDeclaration> symbolReference = JavaParserFacade.get(new ReflectionTypeSolver()).solve(nameE);
assertEquals(true, symbolReference.isSolved());
assertEquals(true, symbolReference.getCorrespondingDeclaration().isParameter());
assertEquals("e", symbolReference.getCorrespondingDeclaration().asParameter().getName());
assertEquals("java.lang.UnsupportedOperationException", symbolReference.getCorrespondingDeclaration().asParameter().getType().asReferenceType().getQualifiedName());
}
use of com.github.javaparser.ast.expr.MethodCallExpr 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());
}
use of com.github.javaparser.ast.expr.MethodCallExpr in project javaparser by javaparser.
the class LambdaResolutionTest method lambdaMapParameter.
@Test
public void lambdaMapParameter() {
CompilationUnit cu = parseSample("Lambda");
com.github.javaparser.ast.body.ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "Agenda");
MethodDeclaration method = Navigator.demandMethod(clazz, "lambdaMap");
ReturnStmt returnStmt = Navigator.findReturnStmt(method);
MethodCallExpr methodCallExpr = (MethodCallExpr) returnStmt.getExpression().get();
Expression expression = methodCallExpr.getArguments().get(0);
JavaParserFacade javaParserFacade = JavaParserFacade.get(new ReflectionTypeSolver());
ResolvedType type = javaParserFacade.getType(expression);
assertEquals("java.util.function.Function<? super java.lang.String, ? extends java.lang.String>", type.describe());
}
use of com.github.javaparser.ast.expr.MethodCallExpr in project javaparser by javaparser.
the class LambdaResolutionTest method lambdaCollectParam.
@Test
public void lambdaCollectParam() {
CompilationUnit cu = parseSample("LambdaCollect");
com.github.javaparser.ast.body.ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "Agenda");
MethodDeclaration method = Navigator.demandMethod(clazz, "lambdaMap");
ReturnStmt returnStmt = Navigator.findReturnStmt(method);
MethodCallExpr methodCallExpr = (MethodCallExpr) returnStmt.getExpression().get();
// Collectors.toList()
Expression expression = methodCallExpr.getArguments().get(0);
JavaParserFacade javaParserFacade = JavaParserFacade.get(new ReflectionTypeSolver());
ResolvedType type = javaParserFacade.getType(expression);
assertEquals("java.util.stream.Collector<T, ? extends java.lang.Object, java.util.List<T>>", type.describe());
}
Aggregations