Search in sources :

Example 16 with IntegerLiteralExpr

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"));
}
Also used : CompilationUnit(com.github.javaparser.ast.CompilationUnit) SingleMemberAnnotationExpr(com.github.javaparser.ast.expr.SingleMemberAnnotationExpr) IntegerLiteralExpr(com.github.javaparser.ast.expr.IntegerLiteralExpr) MarkerAnnotationExpr(com.github.javaparser.ast.expr.MarkerAnnotationExpr) ClassOrInterfaceType(com.github.javaparser.ast.type.ClassOrInterfaceType) JavaParser.parseClassOrInterfaceType(com.github.javaparser.JavaParser.parseClassOrInterfaceType) Name(com.github.javaparser.ast.expr.Name) JavaParser.parseName(com.github.javaparser.JavaParser.parseName) Test(org.junit.Test)

Aggregations

IntegerLiteralExpr (com.github.javaparser.ast.expr.IntegerLiteralExpr)16 Test (org.junit.Test)14 Expression (com.github.javaparser.ast.expr.Expression)9 JavaParser.parseExpression (com.github.javaparser.JavaParser.parseExpression)7 AbstractLexicalPreservingTest (com.github.javaparser.printer.lexicalpreservation.AbstractLexicalPreservingTest)4 ArrayCreationLevel (com.github.javaparser.ast.ArrayCreationLevel)2 CompilationUnit (com.github.javaparser.ast.CompilationUnit)2 Node (com.github.javaparser.ast.Node)2 AnnotationMemberDeclaration (com.github.javaparser.ast.body.AnnotationMemberDeclaration)2 ClassOrInterfaceDeclaration (com.github.javaparser.ast.body.ClassOrInterfaceDeclaration)2 SimpleName (com.github.javaparser.ast.expr.SimpleName)2 JavaParser.parse (com.github.javaparser.JavaParser.parse)1 JavaParser.parseClassOrInterfaceType (com.github.javaparser.JavaParser.parseClassOrInterfaceType)1 JavaParser.parseName (com.github.javaparser.JavaParser.parseName)1 NodeList (com.github.javaparser.ast.NodeList)1 BodyDeclaration (com.github.javaparser.ast.body.BodyDeclaration)1 EnumConstantDeclaration (com.github.javaparser.ast.body.EnumConstantDeclaration)1 EnumDeclaration (com.github.javaparser.ast.body.EnumDeclaration)1 FieldDeclaration (com.github.javaparser.ast.body.FieldDeclaration)1 MethodDeclaration (com.github.javaparser.ast.body.MethodDeclaration)1