use of com.github.javaparser.ast.expr.MethodCallExpr in project javaparser by javaparser.
the class Issue144 method issue144WithCombinedTypeSolver.
@Test
public void issue144WithCombinedTypeSolver() {
CompilationUnit cu = parseSampleWithStandardExtension("issue144/HelloWorld");
ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "HelloWorld");
ExpressionStmt expressionStmt = (ExpressionStmt) clazz.getMethodsByName("main").get(0).getBody().get().getStatement(0);
MethodCallExpr methodCallExpr = (MethodCallExpr) expressionStmt.getExpression();
Expression firstParameter = methodCallExpr.getArgument(0);
JavaParserFacade javaParserFacade = JavaParserFacade.get(new CombinedTypeSolver(typeSolver, new ReflectionTypeSolver(true)));
assertEquals(true, javaParserFacade.solve(firstParameter).isSolved());
}
use of com.github.javaparser.ast.expr.MethodCallExpr in project javaparser by javaparser.
the class Issue156 method testFieldAccessThroughClassAndThis.
@Test
public void testFieldAccessThroughClassAndThis() {
CompilationUnit cu = parseSample("Issue156");
ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "Issue156");
List<MethodCallExpr> methods = clazz.getChildNodes().get(2).getChildNodes().get(1).findAll(MethodCallExpr.class);
TypeSolver typeSolver = new ReflectionTypeSolver();
JavaParserFacade javaParserFacade = JavaParserFacade.get(typeSolver);
assertEquals("char", javaParserFacade.getType(methods.get(0)).describe());
}
use of com.github.javaparser.ast.expr.MethodCallExpr in project javaparser by javaparser.
the class Issue186 method lambdaFlatMapIssue.
@Test
public void lambdaFlatMapIssue() {
CompilationUnit cu = parseSample("Issue186");
ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "JavaTest");
MethodDeclaration methodDeclaration = Navigator.demandMethod(clazz, "foo");
MethodCallExpr methodCallExpr = Navigator.findMethodCall(methodDeclaration, "flatMap").get();
TypeSolver typeSolver = new ReflectionTypeSolver();
JavaParserFacade javaParserFacade = JavaParserFacade.get(typeSolver);
assertEquals("java.util.stream.Stream<java.lang.String>", javaParserFacade.getType(methodCallExpr).describe());
}
use of com.github.javaparser.ast.expr.MethodCallExpr in project javaparser by javaparser.
the class VariadicResolutionTest method selectMostSpecificVariadic.
@Test
public void selectMostSpecificVariadic() {
CompilationUnit cu = parseSample("MethodCalls");
ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "MethodCalls");
MethodDeclaration method = Navigator.demandMethod(clazz, "variadicTest");
List<MethodCallExpr> calls = method.findAll(MethodCallExpr.class);
File src = adaptPath(new File("src/test/resources"));
TypeSolver typeSolver = new CombinedTypeSolver(new ReflectionTypeSolver(), new JavaParserTypeSolver(src));
JavaParserFacade javaParserFacade = JavaParserFacade.get(typeSolver);
MethodUsage call1 = javaParserFacade.solveMethodAsUsage(calls.get(0));
MethodUsage call2 = javaParserFacade.solveMethodAsUsage(calls.get(1));
assertEquals("int", call1.returnType().describe());
assertEquals("void", call2.returnType().describe());
}
use of com.github.javaparser.ast.expr.MethodCallExpr 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());
}
Aggregations