Search in sources :

Example 6 with AnnotationMemberDeclaration

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

the class JavaParserTest method rangeOfAnnotationMemberDeclarationIsCorrect.

@Test
public void rangeOfAnnotationMemberDeclarationIsCorrect() {
    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, 29)), memberDeclaration.getRange().get());
}
Also used : CompilationUnit(com.github.javaparser.ast.CompilationUnit) AnnotationMemberDeclaration(com.github.javaparser.ast.body.AnnotationMemberDeclaration) Test(org.junit.Test)

Example 7 with AnnotationMemberDeclaration

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

the class AnnotationMemberDeclarationTransformationsTest method replacingAnnotation.

@Test
public void replacingAnnotation() {
    AnnotationMemberDeclaration it = consider("@myAnno int foo();");
    it.getAnnotations().set(0, new NormalAnnotationExpr(new Name("myOtherAnno"), new NodeList<>()));
    assertTransformedToString("@myOtherAnno() int foo();", it);
}
Also used : NodeList(com.github.javaparser.ast.NodeList) NormalAnnotationExpr(com.github.javaparser.ast.expr.NormalAnnotationExpr) AnnotationMemberDeclaration(com.github.javaparser.ast.body.AnnotationMemberDeclaration) Name(com.github.javaparser.ast.expr.Name) Test(org.junit.Test) AbstractLexicalPreservingTest(com.github.javaparser.printer.lexicalpreservation.AbstractLexicalPreservingTest)

Example 8 with AnnotationMemberDeclaration

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

the class AnnotationMemberDeclarationTransformationsTest method addingModifiers.

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

Example 9 with AnnotationMemberDeclaration

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

the class AnnotationMemberDeclarationTransformationsTest method changingType.

// Type
@Test
public void changingType() {
    AnnotationMemberDeclaration md = consider("int foo();");
    md.setType("String");
    assertTransformedToString("String foo();", md);
}
Also used : AnnotationMemberDeclaration(com.github.javaparser.ast.body.AnnotationMemberDeclaration) Test(org.junit.Test) AbstractLexicalPreservingTest(com.github.javaparser.printer.lexicalpreservation.AbstractLexicalPreservingTest)

Example 10 with AnnotationMemberDeclaration

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

the class AnnotationMemberDeclarationTransformationsTest method removingAnnotationOnPrevLine.

@Test
public void removingAnnotationOnPrevLine() {
    AnnotationMemberDeclaration it = consider("@myAnno" + EOL + "int foo();");
    it.getAnnotations().remove(0);
    assertTransformedToString("int foo();", it);
}
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