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);
}
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);
}
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"));
}
Aggregations