Search in sources :

Example 1 with EnumConstantDeclaration

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

the class CloneVisitor method visit.

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

Example 2 with EnumConstantDeclaration

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

the class LexicalDifferenceCalculatorTest method simpleEnumConstantDeclaration.

@Test
public void simpleEnumConstantDeclaration() throws IOException {
    EnumConstantDeclaration ecd = considerEcd("A");
    LexicalDifferenceCalculator.CalculatedSyntaxModel csm = new LexicalDifferenceCalculator().calculatedSyntaxModelForNode(ecd);
    int i = 0;
    assertEquals(new LexicalDifferenceCalculator.CsmChild(ecd.getName()), csm.elements.get(i++));
    assertEquals(i, csm.elements.size());
}
Also used : EnumConstantDeclaration(com.github.javaparser.ast.body.EnumConstantDeclaration) Test(org.junit.Test)

Example 3 with EnumConstantDeclaration

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

the class TokenKindGenerator method generateEnumEntry.

private void generateEnumEntry(EnumDeclaration kindEnum, String name, IntegerLiteralExpr kind) {
    final EnumConstantDeclaration enumEntry = new EnumConstantDeclaration(name);
    enumEntry.getArguments().add(kind);
    kindEnum.addEntry(enumEntry);
}
Also used : EnumConstantDeclaration(com.github.javaparser.ast.body.EnumConstantDeclaration)

Example 4 with EnumConstantDeclaration

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

the class PropertyGenerator method generateObservableProperty.

private void generateObservableProperty(EnumDeclaration observablePropertyEnum, PropertyMetaModel property, boolean derived) {
    boolean isAttribute = !Node.class.isAssignableFrom(property.getType());
    String name = property.getName();
    String constantName = camelCaseToScreaming(name.startsWith("is") ? name.substring(2) : name);
    EnumConstantDeclaration enumConstantDeclaration = observablePropertyEnum.addEnumConstant(constantName);
    if (isAttribute) {
        if (property.isEnumSet()) {
            enumConstantDeclaration.addArgument("Type.MULTIPLE_ATTRIBUTE");
        } else {
            enumConstantDeclaration.addArgument("Type.SINGLE_ATTRIBUTE");
        }
    } else {
        if (property.isNodeList()) {
            enumConstantDeclaration.addArgument("Type.MULTIPLE_REFERENCE");
        } else {
            enumConstantDeclaration.addArgument("Type.SINGLE_REFERENCE");
        }
    }
    if (derived) {
        enumConstantDeclaration.addArgument("true");
    }
}
Also used : EnumConstantDeclaration(com.github.javaparser.ast.body.EnumConstantDeclaration) Node(com.github.javaparser.ast.Node)

Example 5 with EnumConstantDeclaration

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

the class EnumDeclarationTransformationsTest method addingConstants.

@Test
public void addingConstants() {
    EnumDeclaration ed = consider("enum A {" + EOL + " E1" + EOL + "}");
    ed.getEntries().addLast(new EnumConstantDeclaration("E2"));
    assertTransformedToString("enum A {" + EOL + " E1," + EOL + " E2" + EOL + "}", ed);
}
Also used : EnumConstantDeclaration(com.github.javaparser.ast.body.EnumConstantDeclaration) EnumDeclaration(com.github.javaparser.ast.body.EnumDeclaration) Test(org.junit.Test) AbstractLexicalPreservingTest(com.github.javaparser.printer.lexicalpreservation.AbstractLexicalPreservingTest)

Aggregations

EnumConstantDeclaration (com.github.javaparser.ast.body.EnumConstantDeclaration)18 EnumDeclaration (com.github.javaparser.ast.body.EnumDeclaration)8 ClassOrInterfaceDeclaration (com.github.javaparser.ast.body.ClassOrInterfaceDeclaration)5 BodyDeclaration (com.github.javaparser.ast.body.BodyDeclaration)4 AnnotationDeclaration (com.github.javaparser.ast.body.AnnotationDeclaration)3 ConstructorDeclaration (com.github.javaparser.ast.body.ConstructorDeclaration)3 FieldDeclaration (com.github.javaparser.ast.body.FieldDeclaration)3 MethodDeclaration (com.github.javaparser.ast.body.MethodDeclaration)3 RecordDeclaration (com.github.javaparser.ast.body.RecordDeclaration)3 VariableDeclarator (com.github.javaparser.ast.body.VariableDeclarator)3 NewClassTree (com.sun.source.tree.NewClassTree)3 ExecutableElement (javax.lang.model.element.ExecutableElement)3 TypeElement (javax.lang.model.element.TypeElement)3 VariableElement (javax.lang.model.element.VariableElement)3 Parameter (com.github.javaparser.ast.body.Parameter)2 ReceiverParameter (com.github.javaparser.ast.body.ReceiverParameter)2 BlockComment (com.github.javaparser.ast.comments.BlockComment)2 Comment (com.github.javaparser.ast.comments.Comment)2 JavadocComment (com.github.javaparser.ast.comments.JavadocComment)2 LineComment (com.github.javaparser.ast.comments.LineComment)2