Search in sources :

Example 11 with AnnotationMemberDeclaration

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

the class AnnotationMemberDeclarationTransformationsTest method replacingModifiers.

@Test
public void replacingModifiers() {
    AnnotationMemberDeclaration md = consider("public int foo();");
    md.setModifiers(EnumSet.of(Modifier.PROTECTED));
    assertTransformedToString("protected int foo();", md);
}
Also used : AnnotationMemberDeclaration(com.github.javaparser.ast.body.AnnotationMemberDeclaration) Test(org.junit.Test) AbstractLexicalPreservingTest(com.github.javaparser.printer.lexicalpreservation.AbstractLexicalPreservingTest)

Example 12 with AnnotationMemberDeclaration

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

the class AnnotationMemberDeclarationTransformationsTest method addingTwoAnnotations.

@Test
public void addingTwoAnnotations() {
    AnnotationMemberDeclaration it = consider("int foo();");
    it.addAnnotation("myAnno");
    it.addAnnotation("myAnno2");
    assertTransformedToString("@myAnno()" + EOL + "@myAnno2()" + 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 13 with AnnotationMemberDeclaration

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

the class CloneVisitor method visit.

@Override
public Node visit(AnnotationMemberDeclaration _n, Object _arg) {
    JavadocComment javaDoc = cloneNodes(_n.getJavaDoc(), _arg);
    List<AnnotationExpr> annotations = visit(_n.getAnnotations(), _arg);
    Type type_ = cloneNodes(_n.getType(), _arg);
    Expression defaultValue = cloneNodes(_n.getDefaultValue(), _arg);
    Comment comment = cloneNodes(_n.getComment(), _arg);
    AnnotationMemberDeclaration r = new AnnotationMemberDeclaration(_n.getBeginLine(), _n.getBeginColumn(), _n.getEndLine(), _n.getEndColumn(), _n.getModifiers(), annotations, type_, _n.getName(), defaultValue);
    r.setComment(comment);
    return r;
}
Also used : JavadocComment(com.github.javaparser.ast.comments.JavadocComment) BlockComment(com.github.javaparser.ast.comments.BlockComment) LineComment(com.github.javaparser.ast.comments.LineComment) Comment(com.github.javaparser.ast.comments.Comment) JavadocComment(com.github.javaparser.ast.comments.JavadocComment) AnnotationMemberDeclaration(com.github.javaparser.ast.body.AnnotationMemberDeclaration)

Example 14 with AnnotationMemberDeclaration

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

the class JavaParserTest method rangeOfAnnotationMemberDeclarationWithArrayTypeIsCorrect.

@Test
public void rangeOfAnnotationMemberDeclarationWithArrayTypeIsCorrect() {
    String code = "@interface AD { String[] foo(); }";
    CompilationUnit cu = JavaParser.parse(code);
    AnnotationMemberDeclaration memberDeclaration = cu.getAnnotationDeclarationByName("AD").get().getMember(0).asAnnotationMemberDeclaration();
    assertEquals(true, memberDeclaration.getRange().isPresent());
    assertEquals(new Range(new Position(1, 17), new Position(1, 31)), memberDeclaration.getRange().get());
}
Also used : CompilationUnit(com.github.javaparser.ast.CompilationUnit) AnnotationMemberDeclaration(com.github.javaparser.ast.body.AnnotationMemberDeclaration) Test(org.junit.Test)

Example 15 with AnnotationMemberDeclaration

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

the class AnnotationMemberDeclarationTransformationsTest method changingName.

// Name
@Test
public void changingName() {
    AnnotationMemberDeclaration md = consider("int foo();");
    md.setName("bar");
    assertTransformedToString("int bar();", md);
}
Also used : 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)21 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