Search in sources :

Example 1 with AnnotationDeclaration

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

the class CloneVisitor method visit.

@Override
public Node visit(AnnotationDeclaration _n, Object _arg) {
    JavadocComment javaDoc = cloneNodes(_n.getJavaDoc(), _arg);
    List<AnnotationExpr> annotations = visit(_n.getAnnotations(), _arg);
    List<BodyDeclaration> members = visit(_n.getMembers(), _arg);
    Comment comment = cloneNodes(_n.getComment(), _arg);
    AnnotationDeclaration r = new AnnotationDeclaration(_n.getBeginLine(), _n.getBeginColumn(), _n.getEndLine(), _n.getEndColumn(), _n.getModifiers(), annotations, _n.getName(), members);
    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) AnnotationDeclaration(com.github.javaparser.ast.body.AnnotationDeclaration) BodyDeclaration(com.github.javaparser.ast.body.BodyDeclaration)

Example 2 with AnnotationDeclaration

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

the class LexicalDifferenceCalculatorTest method annotationDeclarationModifiersExampleModified.

@Test
public void annotationDeclarationModifiersExampleModified() throws IOException {
    considerExample("AnnotationDeclaration_Example1_original");
    AnnotationDeclaration annotationDeclaration = (AnnotationDeclaration) cu.getType(0);
    CsmElement element = ConcreteSyntaxModel.forClass(annotationDeclaration.getClass());
    LexicalDifferenceCalculator.CalculatedSyntaxModel csm = new LexicalDifferenceCalculator().calculatedSyntaxModelAfterPropertyChange(element, annotationDeclaration, ObservableProperty.MODIFIERS, EnumSet.noneOf(Modifier.class), EnumSet.of(Modifier.PUBLIC));
    csm.removeIndentationElements();
    int i = 0;
    assertEquals(new CsmToken(GeneratedJavaParserConstants.PUBLIC), csm.elements.get(i++));
    assertEquals(new CsmToken(spaceTokenKind()), csm.elements.get(i++));
    assertEquals(new CsmToken(GeneratedJavaParserConstants.AT), csm.elements.get(i++));
    assertEquals(new CsmToken(GeneratedJavaParserConstants.INTERFACE), csm.elements.get(i++));
    assertEquals(new CsmToken(spaceTokenKind()), csm.elements.get(i++));
    assertEquals(new LexicalDifferenceCalculator.CsmChild(annotationDeclaration.getName()), csm.elements.get(i++));
    assertEquals(new CsmToken(spaceTokenKind()), csm.elements.get(i++));
    assertEquals(new CsmToken(GeneratedJavaParserConstants.LBRACE), csm.elements.get(i++));
    assertEquals(new CsmToken(eolTokenKind()), csm.elements.get(i++));
    assertEquals(new LexicalDifferenceCalculator.CsmChild(annotationDeclaration.getMember(0)), csm.elements.get(i++));
    assertEquals(new CsmToken(eolTokenKind()), csm.elements.get(i++));
    assertEquals(new LexicalDifferenceCalculator.CsmChild(annotationDeclaration.getMember(1)), csm.elements.get(i++));
    assertEquals(new CsmToken(eolTokenKind()), csm.elements.get(i++));
    assertEquals(new LexicalDifferenceCalculator.CsmChild(annotationDeclaration.getMember(2)), csm.elements.get(i++));
    assertEquals(new CsmToken(eolTokenKind()), csm.elements.get(i++));
    assertEquals(new LexicalDifferenceCalculator.CsmChild(annotationDeclaration.getMember(3)), csm.elements.get(i++));
    assertEquals(new CsmToken(eolTokenKind()), csm.elements.get(i++));
    assertEquals(new LexicalDifferenceCalculator.CsmChild(annotationDeclaration.getMember(4)), csm.elements.get(i++));
    assertEquals(new CsmToken(eolTokenKind()), csm.elements.get(i++));
    assertEquals(new LexicalDifferenceCalculator.CsmChild(annotationDeclaration.getMember(5)), csm.elements.get(i++));
    assertEquals(new CsmToken(eolTokenKind()), csm.elements.get(i++));
    assertEquals(new CsmToken(GeneratedJavaParserConstants.RBRACE), csm.elements.get(i++));
    assertEquals(i, csm.elements.size());
}
Also used : CsmToken(com.github.javaparser.printer.concretesyntaxmodel.CsmToken) AnnotationDeclaration(com.github.javaparser.ast.body.AnnotationDeclaration) CsmElement(com.github.javaparser.printer.concretesyntaxmodel.CsmElement) Modifier(com.github.javaparser.ast.Modifier) Test(org.junit.Test)

Example 3 with AnnotationDeclaration

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

the class LexicalDifferenceCalculatorTest method annotationDeclaratioJavadocExampleOriginal.

@Test
public void annotationDeclaratioJavadocExampleOriginal() throws IOException {
    considerExample("AnnotationDeclaration_Example3_original");
    AnnotationDeclaration annotationDeclaration = (AnnotationDeclaration) cu.getType(0);
    CsmElement element = ConcreteSyntaxModel.forClass(annotationDeclaration.getClass());
    LexicalDifferenceCalculator.CalculatedSyntaxModel csm = new LexicalDifferenceCalculator().calculatedSyntaxModelForNode(element, annotationDeclaration);
    csm.removeIndentationElements();
    int i = 0;
    assertEquals(new CsmToken(GeneratedJavaParserConstants.PUBLIC), csm.elements.get(i++));
    assertEquals(new CsmToken(spaceTokenKind()), csm.elements.get(i++));
    assertEquals(new CsmToken(GeneratedJavaParserConstants.AT), csm.elements.get(i++));
    assertEquals(new CsmToken(GeneratedJavaParserConstants.INTERFACE), csm.elements.get(i++));
    assertEquals(new CsmToken(spaceTokenKind()), csm.elements.get(i++));
    assertEquals(new LexicalDifferenceCalculator.CsmChild(annotationDeclaration.getName()), csm.elements.get(i++));
    assertEquals(new CsmToken(spaceTokenKind()), csm.elements.get(i++));
    assertEquals(new CsmToken(GeneratedJavaParserConstants.LBRACE), csm.elements.get(i++));
    assertEquals(new CsmToken(eolTokenKind()), csm.elements.get(i++));
    assertEquals(new LexicalDifferenceCalculator.CsmChild(annotationDeclaration.getMember(0)), csm.elements.get(i++));
    assertEquals(new CsmToken(eolTokenKind()), csm.elements.get(i++));
    assertEquals(new LexicalDifferenceCalculator.CsmChild(annotationDeclaration.getMember(1)), csm.elements.get(i++));
    assertEquals(new CsmToken(eolTokenKind()), csm.elements.get(i++));
    assertEquals(new LexicalDifferenceCalculator.CsmChild(annotationDeclaration.getMember(2)), csm.elements.get(i++));
    assertEquals(new CsmToken(eolTokenKind()), csm.elements.get(i++));
    assertEquals(new LexicalDifferenceCalculator.CsmChild(annotationDeclaration.getMember(3)), csm.elements.get(i++));
    assertEquals(new CsmToken(eolTokenKind()), csm.elements.get(i++));
    assertEquals(new LexicalDifferenceCalculator.CsmChild(annotationDeclaration.getMember(4)), csm.elements.get(i++));
    assertEquals(new CsmToken(eolTokenKind()), csm.elements.get(i++));
    assertEquals(new LexicalDifferenceCalculator.CsmChild(annotationDeclaration.getMember(5)), csm.elements.get(i++));
    assertEquals(new CsmToken(eolTokenKind()), csm.elements.get(i++));
    assertEquals(new CsmToken(GeneratedJavaParserConstants.RBRACE), csm.elements.get(i++));
    assertEquals(i, csm.elements.size());
}
Also used : CsmToken(com.github.javaparser.printer.concretesyntaxmodel.CsmToken) AnnotationDeclaration(com.github.javaparser.ast.body.AnnotationDeclaration) CsmElement(com.github.javaparser.printer.concretesyntaxmodel.CsmElement) Test(org.junit.Test)

Example 4 with AnnotationDeclaration

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

the class LexicalDifferenceCalculatorTest method annotationDeclarationModifiersExampleOriginal.

@Test
public void annotationDeclarationModifiersExampleOriginal() throws IOException {
    considerExample("AnnotationDeclaration_Example1_original");
    AnnotationDeclaration annotationDeclaration = (AnnotationDeclaration) cu.getType(0);
    CsmElement element = ConcreteSyntaxModel.forClass(annotationDeclaration.getClass());
    LexicalDifferenceCalculator.CalculatedSyntaxModel csm = new LexicalDifferenceCalculator().calculatedSyntaxModelForNode(element, annotationDeclaration);
    csm.removeIndentationElements();
    int i = 0;
    assertEquals(new CsmToken(GeneratedJavaParserConstants.AT), csm.elements.get(i++));
    assertEquals(new CsmToken(GeneratedJavaParserConstants.INTERFACE), csm.elements.get(i++));
    assertEquals(new CsmToken(spaceTokenKind()), csm.elements.get(i++));
    assertEquals(new LexicalDifferenceCalculator.CsmChild(annotationDeclaration.getName()), csm.elements.get(i++));
    assertEquals(new CsmToken(spaceTokenKind()), csm.elements.get(i++));
    assertEquals(new CsmToken(GeneratedJavaParserConstants.LBRACE), csm.elements.get(i++));
    assertEquals(new CsmToken(eolTokenKind()), csm.elements.get(i++));
    assertEquals(new LexicalDifferenceCalculator.CsmChild(annotationDeclaration.getMember(0)), csm.elements.get(i++));
    assertEquals(new CsmToken(eolTokenKind()), csm.elements.get(i++));
    assertEquals(new LexicalDifferenceCalculator.CsmChild(annotationDeclaration.getMember(1)), csm.elements.get(i++));
    assertEquals(new CsmToken(eolTokenKind()), csm.elements.get(i++));
    assertEquals(new LexicalDifferenceCalculator.CsmChild(annotationDeclaration.getMember(2)), csm.elements.get(i++));
    assertEquals(new CsmToken(eolTokenKind()), csm.elements.get(i++));
    assertEquals(new LexicalDifferenceCalculator.CsmChild(annotationDeclaration.getMember(3)), csm.elements.get(i++));
    assertEquals(new CsmToken(eolTokenKind()), csm.elements.get(i++));
    assertEquals(new LexicalDifferenceCalculator.CsmChild(annotationDeclaration.getMember(4)), csm.elements.get(i++));
    assertEquals(new CsmToken(eolTokenKind()), csm.elements.get(i++));
    assertEquals(new LexicalDifferenceCalculator.CsmChild(annotationDeclaration.getMember(5)), csm.elements.get(i++));
    assertEquals(new CsmToken(eolTokenKind()), csm.elements.get(i++));
    assertEquals(new CsmToken(GeneratedJavaParserConstants.RBRACE), csm.elements.get(i++));
    assertEquals(i, csm.elements.size());
}
Also used : CsmToken(com.github.javaparser.printer.concretesyntaxmodel.CsmToken) AnnotationDeclaration(com.github.javaparser.ast.body.AnnotationDeclaration) CsmElement(com.github.javaparser.printer.concretesyntaxmodel.CsmElement) Test(org.junit.Test)

Example 5 with AnnotationDeclaration

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

the class CompilationUnitBuildersTest method testAddAnnotationDeclaration.

@Test
public void testAddAnnotationDeclaration() {
    AnnotationDeclaration myAnnotationDeclaration = cu.addAnnotationDeclaration("test");
    assertEquals(1, cu.getTypes().size());
    assertEquals("test", cu.getType(0).getNameAsString());
    assertTrue(myAnnotationDeclaration.isPublic());
    assertEquals(AnnotationDeclaration.class, cu.getType(0).getClass());
}
Also used : AnnotationDeclaration(com.github.javaparser.ast.body.AnnotationDeclaration) Test(org.junit.Test)

Aggregations

AnnotationDeclaration (com.github.javaparser.ast.body.AnnotationDeclaration)13 Test (org.junit.Test)6 CsmElement (com.github.javaparser.printer.concretesyntaxmodel.CsmElement)5 CsmToken (com.github.javaparser.printer.concretesyntaxmodel.CsmToken)5 ClassOrInterfaceDeclaration (com.github.javaparser.ast.body.ClassOrInterfaceDeclaration)4 EnumDeclaration (com.github.javaparser.ast.body.EnumDeclaration)4 EnumConstantDeclaration (com.github.javaparser.ast.body.EnumConstantDeclaration)3 BodyDeclaration (com.github.javaparser.ast.body.BodyDeclaration)2 FieldDeclaration (com.github.javaparser.ast.body.FieldDeclaration)2 RecordDeclaration (com.github.javaparser.ast.body.RecordDeclaration)2 JavadocComment (com.github.javaparser.ast.comments.JavadocComment)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 ImportDeclaration (com.github.javaparser.ast.ImportDeclaration)1 Modifier (com.github.javaparser.ast.Modifier)1 NodeList (com.github.javaparser.ast.NodeList)1 ConstructorDeclaration (com.github.javaparser.ast.body.ConstructorDeclaration)1 MethodDeclaration (com.github.javaparser.ast.body.MethodDeclaration)1 Parameter (com.github.javaparser.ast.body.Parameter)1 ReceiverParameter (com.github.javaparser.ast.body.ReceiverParameter)1