use of com.github.javaparser.ast.CompilationUnit in project javaparser by javaparser.
the class JavaParserTest method rangeOfAnnotationMemberDeclarationIsCorrect.
@Test
public void rangeOfAnnotationMemberDeclarationIsCorrect() {
String code = "@interface AD { String foo(); }";
CompilationUnit cu = JavaParser.parse(code);
AnnotationMemberDeclaration memberDeclaration = cu.getAnnotationDeclarationByName("AD").get().getMember(0).asAnnotationMemberDeclaration();
assertEquals(true, memberDeclaration.getRange().isPresent());
assertEquals(new Range(new Position(1, 17), new Position(1, 29)), memberDeclaration.getRange().get());
}
use of com.github.javaparser.ast.CompilationUnit in project javaparser by javaparser.
the class ModuleDeclarationTest method jlsExample2HasAnOpenModule.
@Test
public void jlsExample2HasAnOpenModule() {
CompilationUnit cu = parse("open module M.N {}");
ModuleDeclaration module = cu.getModule().get();
assertEquals("M.N", module.getNameAsString());
assertEquals(true, module.isOpen());
}
use of com.github.javaparser.ast.CompilationUnit in project javaparser by javaparser.
the class ModuleDeclarationTest method testPrettyPrinting.
@Test
public void testPrettyPrinting() {
CompilationUnit cu = parse("@Foo(1) @Foo(2) @Bar " + "module M.N {" + " requires A.B;" + " requires transitive C.D;" + " requires static E.F;" + " requires transitive static G.H;" + "" + " exports P.Q;" + " exports R.S to T1.U1, T2.U2;" + "" + " opens P.Q;" + " opens R.S to T1.U1, T2.U2;" + "" + " uses V.W;" + " provides X.Y with Z1.Z2, Z3.Z4;" + "}");
assertEquals("@Foo(1) @Foo(2) @Bar " + EOL + "module M.N {" + EOL + " requires A.B;" + EOL + " requires transitive C.D;" + EOL + " requires static E.F;" + EOL + " requires static transitive G.H;" + EOL + " exports P.Q;" + EOL + " exports R.S to T1.U1, T2.U2;" + EOL + " opens P.Q;" + EOL + " opens R.S to T1.U1, T2.U2;" + EOL + " uses V.W;" + EOL + " provides X.Y with Z1.Z2, Z3.Z4;" + EOL + "}" + EOL, cu.toString());
}
use of com.github.javaparser.ast.CompilationUnit in project javaparser by javaparser.
the class ModuleDeclarationTest method issue988RequireTransitiveShouldRequireAModuleCalledTransitive.
@Test
public void issue988RequireTransitiveShouldRequireAModuleCalledTransitive() {
CompilationUnit cu = parse("module X { requires transitive; }");
ModuleRequiresStmt requiresTransitive = (ModuleRequiresStmt) cu.getModule().get().getModuleStmts().get(0);
assertEquals("transitive", requiresTransitive.getNameAsString());
assertEquals(IDENTIFIER, requiresTransitive.getName().getTokenRange().get().getBegin().getKind());
}
use of com.github.javaparser.ast.CompilationUnit in project javaparser by javaparser.
the class ConcreteSyntaxModelAcceptanceTest method printingExamplePrettyPrintVisitor.
@Test
public void printingExamplePrettyPrintVisitor() throws IOException {
CompilationUnit cu = JavaParser.parse(rootDir.resolve("com/github/javaparser/printer/PrettyPrintVisitor.java"));
assertEquals(prettyPrintedExpectation("PrettyPrintVisitor"), prettyPrint(cu));
}
Aggregations