use of com.github.javaparser.ast.CompilationUnit in project javaparser by javaparser.
the class MultiCatchMethodCallExprTest method issue1482.
@Test
public void issue1482() {
CompilationUnit cu = parseSample("Issue1482");
cu.accept(new Visitor(), null);
}
use of com.github.javaparser.ast.CompilationUnit in project javaparser by javaparser.
the class JavaParserAnonymousClassDeclarationTest method callingSuperClassInnerClassMethod.
@Test
public void callingSuperClassInnerClassMethod() {
CompilationUnit cu = parseSample("AnonymousClassDeclarations");
ClassOrInterfaceDeclaration aClass = Navigator.demandClass(cu, "AnonymousClassDeclarations");
MethodDeclaration method = Navigator.demandMethod(aClass, "fooBar2");
MethodCallExpr methodCall = Navigator.findMethodCall(method, "innerClassMethod").get();
CombinedTypeSolver combinedTypeSolver = new CombinedTypeSolver();
combinedTypeSolver.add(new ReflectionTypeSolver());
MethodUsage methodUsage = JavaParserFacade.get(combinedTypeSolver).solveMethodAsUsage(methodCall);
assertThat(methodUsage.getQualifiedSignature(), is("AnonymousClassDeclarations.DoFn.ProcessContext.innerClassMethod()"));
}
use of com.github.javaparser.ast.CompilationUnit in project javaparser by javaparser.
the class JavaParserClassDeclarationTest method testHasAnnotation.
// hasAnnotation
@Test
public void testHasAnnotation() throws IOException, ParseException {
TypeSolver typeSolver = new ReflectionTypeSolver();
CompilationUnit cu = JavaParser.parse(adaptPath(new File("src/test/resources/Annotations.java.txt")));
JavaParserClassDeclaration ca = new JavaParserClassDeclaration(Navigator.demandClass(cu, "CA"), typeSolver);
assertEquals(true, ca.hasAnnotation("foo.bar.MyAnnotation"));
assertEquals(false, ca.hasAnnotation("foo.bar.MyAnnotation2"));
assertEquals(false, ca.hasAnnotation("MyAnnotation"));
assertEquals(false, ca.hasAnnotation("foo.bar.MyUnexistingAnnotation"));
JavaParserClassDeclaration cb = new JavaParserClassDeclaration(Navigator.demandClass(cu, "CB"), typeSolver);
assertEquals(true, cb.hasAnnotation("foo.bar.MyAnnotation"));
assertEquals(true, cb.hasAnnotation("foo.bar.MyAnnotation2"));
assertEquals(false, cb.hasAnnotation("MyAnnotation"));
assertEquals(false, cb.hasAnnotation("foo.bar.MyUnexistingAnnotation"));
}
use of com.github.javaparser.ast.CompilationUnit in project javaparser by javaparser.
the class Issue257 method issue257.
@Test
public void issue257() throws FileNotFoundException {
String pathToSourceFile = adaptPath("src/test/resources/issue257/A.java.txt");
CompilationUnit cu = JavaParser.parse(new File(pathToSourceFile));
Statement statement = cu.getClassByName("A").get().getMethodsByName("run").get(0).getBody().get().getStatement(0);
ExpressionStmt expressionStmt = (ExpressionStmt) statement;
Expression expression = expressionStmt.getExpression();
JavaParserFacade.get(typeSolver).getType(expression);
}
use of com.github.javaparser.ast.CompilationUnit in project javaparser by javaparser.
the class PrettyPrintVisitorTest method printLambdaIntersectionTypeReturn.
@Test
public void printLambdaIntersectionTypeReturn() {
String code = "class A {" + EOL + " Object f() {" + EOL + " return (Comparator<Map.Entry<K, V>> & Serializable)(c1, c2) -> c1.getKey().compareTo(c2.getKey()); " + EOL + "}}";
CompilationUnit cu = JavaParser.parse(code);
MethodDeclaration methodDeclaration = (MethodDeclaration) cu.getType(0).getMember(0);
assertEquals("return (Comparator<Map.Entry<K, V>> & Serializable) (c1, c2) -> c1.getKey().compareTo(c2.getKey());", print(methodDeclaration.getBody().get().getStatements().get(0)));
}
Aggregations