Search in sources :

Example 6 with MarkerAnnotationExpr

use of com.github.javaparser.ast.expr.MarkerAnnotationExpr in project javaparser by javaparser.

the class ArrayTypeTest method getFieldDeclarationWithArrays.

@Test
public void getFieldDeclarationWithArrays() {
    FieldDeclaration fieldDeclaration = parseBodyDeclaration("@C int @A[] @B[] a @X[] @Y[];").asFieldDeclaration();
    ArrayType arrayType1 = fieldDeclaration.getVariable(0).getType().asArrayType();
    ArrayType arrayType2 = arrayType1.getComponentType().asArrayType();
    ArrayType arrayType3 = arrayType2.getComponentType().asArrayType();
    ArrayType arrayType4 = arrayType3.getComponentType().asArrayType();
    PrimitiveType elementType = arrayType4.getComponentType().asPrimitiveType();
    assertThat(arrayType1.getAnnotations()).containsExactly(new MarkerAnnotationExpr(parseName("A")));
    assertThat(arrayType2.getAnnotations()).containsExactly(new MarkerAnnotationExpr(parseName("B")));
    assertThat(arrayType3.getAnnotations()).containsExactly(new MarkerAnnotationExpr(parseName("X")));
    assertThat(arrayType4.getAnnotations()).containsExactly(new MarkerAnnotationExpr(parseName("Y")));
    assertThat(elementType.getType()).isEqualTo(PrimitiveType.Primitive.INT);
    assertThat(fieldDeclaration.getAnnotations()).containsExactly(new MarkerAnnotationExpr(parseName("C")));
    assertThat(arrayType1.getParentNode().get().getParentNode().get()).isSameAs(fieldDeclaration);
}
Also used : MarkerAnnotationExpr(com.github.javaparser.ast.expr.MarkerAnnotationExpr) FieldDeclaration(com.github.javaparser.ast.body.FieldDeclaration) Test(org.junit.Test)

Example 7 with MarkerAnnotationExpr

use of com.github.javaparser.ast.expr.MarkerAnnotationExpr in project javaparser by javaparser.

the class ArrayTypeTest method getVariableDeclarationWithArrays.

@Test
public void getVariableDeclarationWithArrays() {
    ExpressionStmt variableDeclarationStatement = parseStatement("@C int @A[] @B[] a @X[] @Y[];").asExpressionStmt();
    VariableDeclarationExpr variableDeclarationExpr = variableDeclarationStatement.getExpression().asVariableDeclarationExpr();
    ArrayType arrayType1 = variableDeclarationExpr.getVariable(0).getType().asArrayType();
    ArrayType arrayType2 = arrayType1.getComponentType().asArrayType();
    ArrayType arrayType3 = arrayType2.getComponentType().asArrayType();
    ArrayType arrayType4 = arrayType3.getComponentType().asArrayType();
    PrimitiveType elementType = arrayType4.getComponentType().asPrimitiveType();
    assertThat(arrayType1.getAnnotations()).containsExactly(new MarkerAnnotationExpr(parseName("A")));
    assertThat(arrayType2.getAnnotations()).containsExactly(new MarkerAnnotationExpr(parseName("B")));
    assertThat(arrayType3.getAnnotations()).containsExactly(new MarkerAnnotationExpr(parseName("X")));
    assertThat(arrayType4.getAnnotations()).containsExactly(new MarkerAnnotationExpr(parseName("Y")));
    assertThat(elementType.getType()).isEqualTo(PrimitiveType.Primitive.INT);
    assertThat(variableDeclarationExpr.getAnnotations()).containsExactly(new MarkerAnnotationExpr(parseName("C")));
    assertThat(arrayType1.getParentNode().get().getParentNode().get()).isSameAs(variableDeclarationExpr);
}
Also used : VariableDeclarationExpr(com.github.javaparser.ast.expr.VariableDeclarationExpr) MarkerAnnotationExpr(com.github.javaparser.ast.expr.MarkerAnnotationExpr) ExpressionStmt(com.github.javaparser.ast.stmt.ExpressionStmt) Test(org.junit.Test)

Example 8 with MarkerAnnotationExpr

use of com.github.javaparser.ast.expr.MarkerAnnotationExpr 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

MarkerAnnotationExpr (com.github.javaparser.ast.expr.MarkerAnnotationExpr)8 Test (org.junit.Test)6 MethodDeclaration (com.github.javaparser.ast.body.MethodDeclaration)2 Parameter (com.github.javaparser.ast.body.Parameter)2 SingleMemberAnnotationExpr (com.github.javaparser.ast.expr.SingleMemberAnnotationExpr)2 JavaParser.parseClassOrInterfaceType (com.github.javaparser.JavaParser.parseClassOrInterfaceType)1 JavaParser.parseName (com.github.javaparser.JavaParser.parseName)1 CompilationUnit (com.github.javaparser.ast.CompilationUnit)1 NodeList (com.github.javaparser.ast.NodeList)1 FieldDeclaration (com.github.javaparser.ast.body.FieldDeclaration)1 Expression (com.github.javaparser.ast.expr.Expression)1 IntegerLiteralExpr (com.github.javaparser.ast.expr.IntegerLiteralExpr)1 MemberValuePair (com.github.javaparser.ast.expr.MemberValuePair)1 Name (com.github.javaparser.ast.expr.Name)1 NormalAnnotationExpr (com.github.javaparser.ast.expr.NormalAnnotationExpr)1 VariableDeclarationExpr (com.github.javaparser.ast.expr.VariableDeclarationExpr)1 ExpressionStmt (com.github.javaparser.ast.stmt.ExpressionStmt)1 ClassOrInterfaceType (com.github.javaparser.ast.type.ClassOrInterfaceType)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1