use of com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade 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.symbolsolver.javaparsermodel.JavaParserFacade in project javaparser by javaparser.
the class Issue235 method issue235.
@Test
public void issue235() {
CompilationUnit cu = parseSample("Issue235");
ClassOrInterfaceDeclaration cls = Navigator.demandClassOrInterface(cu, "Foo");
TypeSolver typeSolver = new ReflectionTypeSolver();
JavaParserFacade javaParserFacade = JavaParserFacade.get(typeSolver);
MethodDeclaration m = Navigator.demandMethod(cls, this.method);
ExpressionStmt stmt = (ExpressionStmt) m.getBody().get().getStatements().get(0);
ObjectCreationExpr expression = (ObjectCreationExpr) stmt.getExpression();
Assert.assertNotNull(javaParserFacade.convertToUsage(expression.getType()));
}
use of com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade in project javaparser by javaparser.
the class Issue113 method issue113providedCodeDoesNotCrash.
@Test
public void issue113providedCodeDoesNotCrash() throws FileNotFoundException {
String pathToSourceFile = adaptPath("src/test/resources/issue113/com/foo/Widget.java");
CompilationUnit cu = JavaParser.parse(new File(pathToSourceFile));
JavaParserFacade parserFacade = JavaParserFacade.get(typeSolver);
MethodDeclaration methodDeclaration = cu.findAll(MethodDeclaration.class).stream().filter(node -> node.getName().getIdentifier().equals("doSomething")).findAny().orElse(null);
methodDeclaration.findAll(MethodCallExpr.class).forEach(parserFacade::solve);
}
use of com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade 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.symbolsolver.javaparsermodel.JavaParserFacade 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