use of com.github.javaparser.ast.expr.IntegerLiteralExpr in project javaparser by javaparser.
the class ModuleDeclarationTest method jlsExample1.
@Test
public void jlsExample1() {
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;" + "}");
ModuleDeclaration module = cu.getModule().get();
assertEquals("M.N", module.getNameAsString());
assertEquals(false, module.isOpen());
assertThat(module.getAnnotations()).containsExactly(new SingleMemberAnnotationExpr(new Name("Foo"), new IntegerLiteralExpr("1")), new SingleMemberAnnotationExpr(new Name("Foo"), new IntegerLiteralExpr("2")), new MarkerAnnotationExpr(new Name("Bar")));
ModuleRequiresStmt moduleRequiresStmt = module.getModuleStmts().get(0).asModuleRequiresStmt();
assertThat(moduleRequiresStmt.getNameAsString()).isEqualTo("A.B");
assertThat(moduleRequiresStmt.getModifiers()).isEmpty();
ModuleExportsStmt moduleExportsStmt = module.getModuleStmts().get(5).asModuleExportsStmt();
assertThat(moduleExportsStmt.getNameAsString()).isEqualTo("R.S");
assertThat(moduleExportsStmt.getModuleNames()).containsExactly(parseName("T1.U1"), parseName("T2.U2"));
ModuleOpensStmt moduleOpensStmt = module.getModuleStmts().get(7).asModuleOpensStmt();
assertThat(moduleOpensStmt.getNameAsString()).isEqualTo("R.S");
assertThat(moduleOpensStmt.getModuleNames()).containsExactly(parseName("T1.U1"), parseName("T2.U2"));
ModuleUsesStmt moduleUsesStmt = module.getModuleStmts().get(8).asModuleUsesStmt();
assertThat(moduleUsesStmt.getType().toString()).isEqualTo("V.W");
ModuleProvidesStmt moduleProvidesStmt = module.getModuleStmts().get(9).asModuleProvidesStmt();
assertThat(moduleProvidesStmt.getType().toString()).isEqualTo("X.Y");
assertThat(moduleProvidesStmt.getWithTypes()).containsExactly(new ClassOrInterfaceType(parseClassOrInterfaceType("Z1"), "Z2"), new ClassOrInterfaceType(parseClassOrInterfaceType("Z3"), "Z4"));
}
Aggregations