Search in sources :

Example 1 with AnnotationMemberDeclaration

use of com.github.javaparser.ast.body.AnnotationMemberDeclaration in project javaparser by javaparser.

the class AnnotationDeclarationTransformationsTest method replacingMember.

@Test
public void replacingMember() throws IOException {
    considerExample("AnnotationDeclaration_Example3_original");
    cu.getAnnotationDeclarationByName("ClassPreamble").get().setMember(2, new AnnotationMemberDeclaration(EnumSet.noneOf(Modifier.class), PrimitiveType.intType(), "foo", null));
    assertTransformed("AnnotationDeclaration_Example7", cu);
}
Also used : AnnotationMemberDeclaration(com.github.javaparser.ast.body.AnnotationMemberDeclaration) Test(org.junit.Test) AbstractLexicalPreservingTest(com.github.javaparser.printer.lexicalpreservation.AbstractLexicalPreservingTest)

Example 2 with AnnotationMemberDeclaration

use of com.github.javaparser.ast.body.AnnotationMemberDeclaration in project javaparser by javaparser.

the class AnnotationMemberDeclarationTransformationsTest method replacingJavadoc.

@Test
public void replacingJavadoc() {
    AnnotationMemberDeclaration it = consider("/** Cool this annotation!*/ int foo();");
    it.setJavadocComment("Super extra cool this annotation!!!");
    assertTransformedToString("@interface AD { /** Super extra cool this annotation!!!*/ int foo(); }", it.getParentNode().get());
}
Also used : AnnotationMemberDeclaration(com.github.javaparser.ast.body.AnnotationMemberDeclaration) Test(org.junit.Test) AbstractLexicalPreservingTest(com.github.javaparser.printer.lexicalpreservation.AbstractLexicalPreservingTest)

Example 3 with AnnotationMemberDeclaration

use of com.github.javaparser.ast.body.AnnotationMemberDeclaration in project javaparser by javaparser.

the class AnnotationMemberDeclarationTransformationsTest method addingJavadoc.

// Javadoc
@Test
public void addingJavadoc() {
    AnnotationMemberDeclaration it = consider("int foo();");
    it.setJavadocComment("Cool this annotation!");
    assertTransformedToString("@interface AD { /** Cool this annotation!*/" + EOL + "int foo(); }", it.getParentNode().get());
}
Also used : AnnotationMemberDeclaration(com.github.javaparser.ast.body.AnnotationMemberDeclaration) Test(org.junit.Test) AbstractLexicalPreservingTest(com.github.javaparser.printer.lexicalpreservation.AbstractLexicalPreservingTest)

Example 4 with AnnotationMemberDeclaration

use of com.github.javaparser.ast.body.AnnotationMemberDeclaration in project javaparser by javaparser.

the class AnnotationMemberDeclarationTransformationsTest method addingAnnotation.

// Annotations
@Test
public void addingAnnotation() {
    AnnotationMemberDeclaration it = consider("int foo();");
    it.addAnnotation("myAnno");
    assertTransformedToString("@myAnno()" + EOL + "int foo();", it);
}
Also used : AnnotationMemberDeclaration(com.github.javaparser.ast.body.AnnotationMemberDeclaration) Test(org.junit.Test) AbstractLexicalPreservingTest(com.github.javaparser.printer.lexicalpreservation.AbstractLexicalPreservingTest)

Example 5 with AnnotationMemberDeclaration

use of com.github.javaparser.ast.body.AnnotationMemberDeclaration in project javaparser by javaparser.

the class AnnotationMemberDeclarationTransformationsTest method replacingDefaultValue.

@Test
public void replacingDefaultValue() {
    AnnotationMemberDeclaration md = consider("int foo() default 10;");
    md.setDefaultValue(new IntegerLiteralExpr("11"));
    assertTransformedToString("int foo() default 11;", md);
}
Also used : IntegerLiteralExpr(com.github.javaparser.ast.expr.IntegerLiteralExpr) AnnotationMemberDeclaration(com.github.javaparser.ast.body.AnnotationMemberDeclaration) Test(org.junit.Test) AbstractLexicalPreservingTest(com.github.javaparser.printer.lexicalpreservation.AbstractLexicalPreservingTest)

Aggregations

AnnotationMemberDeclaration (com.github.javaparser.ast.body.AnnotationMemberDeclaration)22 Test (org.junit.Test)20 AbstractLexicalPreservingTest (com.github.javaparser.printer.lexicalpreservation.AbstractLexicalPreservingTest)18 CompilationUnit (com.github.javaparser.ast.CompilationUnit)2 IntegerLiteralExpr (com.github.javaparser.ast.expr.IntegerLiteralExpr)2 Modifier (com.github.javaparser.ast.Modifier)1 NodeList (com.github.javaparser.ast.NodeList)1 BlockComment (com.github.javaparser.ast.comments.BlockComment)1 Comment (com.github.javaparser.ast.comments.Comment)1 JavadocComment (com.github.javaparser.ast.comments.JavadocComment)1 LineComment (com.github.javaparser.ast.comments.LineComment)1 Name (com.github.javaparser.ast.expr.Name)1 NormalAnnotationExpr (com.github.javaparser.ast.expr.NormalAnnotationExpr)1