use of com.github.javaparser.ast.CompilationUnit in project javaparser by javaparser.
the class Issue185 method testIssue.
@Test
public void testIssue() throws FileNotFoundException {
File src = adaptPath(new File("src/test/resources/recursion-issue"));
CombinedTypeSolver combinedTypeSolver = new CombinedTypeSolver();
combinedTypeSolver.add(new JavaParserTypeSolver(src));
combinedTypeSolver.add(new ReflectionTypeSolver());
CompilationUnit agendaCu = JavaParser.parse(adaptPath(new File("src/test/resources/recursion-issue/Usage.java")));
MethodCallExpr foo = Navigator.findMethodCall(agendaCu, "foo").get();
assertNotNull(foo);
JavaParserFacade.get(combinedTypeSolver).getType(foo);
}
use of com.github.javaparser.ast.CompilationUnit in project javaparser by javaparser.
the class Issue186 method lambdaPrimitivesIssue.
@Test
public void lambdaPrimitivesIssue() {
CompilationUnit cu = parseSample("Issue186");
ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "JavaTest");
MethodDeclaration methodDeclaration = Navigator.demandMethod(clazz, "bar");
List<LambdaExpr> lambdas = methodDeclaration.findAll(LambdaExpr.class);
TypeSolver typeSolver = new ReflectionTypeSolver();
JavaParserFacade javaParserFacade = JavaParserFacade.get(typeSolver);
assertEquals("java.util.function.Predicate<? super java.lang.String>", javaParserFacade.getType(lambdas.get(0)).describe());
assertEquals("java.util.function.Function<? super java.lang.String, ? extends java.lang.Integer>", javaParserFacade.getType(lambdas.get(1)).describe());
assertEquals("java.util.function.Predicate<? super java.lang.Integer>", javaParserFacade.getType(lambdas.get(2)).describe());
}
use of com.github.javaparser.ast.CompilationUnit in project javaparser by javaparser.
the class Issue200 method issue200.
@Test
public void issue200() {
CompilationUnit cu = parseSample("Issue200");
ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "JavaTest");
MethodDeclaration methodDeclaration = Navigator.demandMethod(clazz, "foo");
TypeSolver typeSolver = new ReflectionTypeSolver();
JavaParserFacade javaParserFacade = JavaParserFacade.get(typeSolver);
List<ReturnStmt> nodesByType = methodDeclaration.findAll(ReturnStmt.class);
assertEquals("java.util.stream.Stream<JavaTest.Solved>", javaParserFacade.getType((nodesByType.get(0)).getExpression().get()).describe());
}
use of com.github.javaparser.ast.CompilationUnit in project javaparser by javaparser.
the class Issue228 method testSolvingMethodWitPrimitiveParameterTypeAsUsage.
@Test
public void testSolvingMethodWitPrimitiveParameterTypeAsUsage() {
String code = "class Test { " + " long l = call(1); " + " long call(final long i) { " + " return i; " + " }" + "}";
CompilationUnit cu = JavaParser.parse(code);
MethodCallExpr methodCall = cu.findAll(MethodCallExpr.class).get(0);
JavaParserFacade parserFacade = JavaParserFacade.get(new ReflectionTypeSolver());
MethodUsage solvedCall = parserFacade.solveMethodAsUsage(methodCall);
assertEquals("long", solvedCall.getParamType(0).describe());
}
use of com.github.javaparser.ast.CompilationUnit in project javaparser by javaparser.
the class Issue113 method issue113superClassIsResolvedCorrectly.
@Test
public void issue113superClassIsResolvedCorrectly() throws FileNotFoundException {
String pathToSourceFile = adaptPath("src/test/resources/issue113/com/foo/Widget.java");
CompilationUnit cu = JavaParser.parse(new File(pathToSourceFile));
JavaParserClassDeclaration jssExtendedWidget = new JavaParserClassDeclaration(cu.getClassByName("Widget").get(), typeSolver);
ResolvedReferenceType superClass = jssExtendedWidget.getSuperClass();
assertEquals("com.foo.base.Widget", superClass.getQualifiedName());
}
Aggregations