Search in sources :

Example 11 with EnumConstantDeclaration

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

the class DumpVisitor method visit.

@Override
public void visit(final EnumDeclaration n, final Object arg) {
    printJavaComment(n.getComment(), arg);
    printJavadoc(n.getJavaDoc(), arg);
    printMemberAnnotations(n.getAnnotations(), arg);
    printModifiers(n.getModifiers());
    printer.print("enum ");
    printer.print(n.getName());
    if (n.getImplements() != null) {
        printer.print(" implements ");
        for (final Iterator<ClassOrInterfaceType> i = n.getImplements().iterator(); i.hasNext(); ) {
            final ClassOrInterfaceType c = i.next();
            c.accept(this, arg);
            if (i.hasNext()) {
                printer.print(", ");
            }
        }
    }
    printer.printLn(" {");
    printer.indent();
    if (n.getEntries() != null) {
        printer.printLn();
        for (final Iterator<EnumConstantDeclaration> i = n.getEntries().iterator(); i.hasNext(); ) {
            final EnumConstantDeclaration e = i.next();
            e.accept(this, arg);
            if (i.hasNext()) {
                printer.print(", ");
            }
        }
    }
    if (n.getMembers() != null) {
        printer.printLn(";");
        printMembers(n.getMembers(), arg);
    } else {
        if (n.getEntries() != null) {
            printer.printLn();
        }
    }
    printer.unindent();
    printer.print("}");
}
Also used : EnumConstantDeclaration(com.github.javaparser.ast.body.EnumConstantDeclaration)

Example 12 with EnumConstantDeclaration

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

the class CloneVisitor method visit.

@Override
public Node visit(EnumDeclaration _n, Object _arg) {
    JavadocComment javaDoc = cloneNodes(_n.getJavaDoc(), _arg);
    List<AnnotationExpr> annotations = visit(_n.getAnnotations(), _arg);
    List<ClassOrInterfaceType> implementsList = visit(_n.getImplements(), _arg);
    List<EnumConstantDeclaration> entries = visit(_n.getEntries(), _arg);
    List<BodyDeclaration> members = visit(_n.getMembers(), _arg);
    Comment comment = cloneNodes(_n.getComment(), _arg);
    EnumDeclaration r = new EnumDeclaration(_n.getBeginLine(), _n.getBeginColumn(), _n.getEndLine(), _n.getEndColumn(), _n.getModifiers(), annotations, _n.getName(), implementsList, entries, members);
    r.setComment(comment);
    return r;
}
Also used : EnumConstantDeclaration(com.github.javaparser.ast.body.EnumConstantDeclaration) 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) BodyDeclaration(com.github.javaparser.ast.body.BodyDeclaration) EnumDeclaration(com.github.javaparser.ast.body.EnumDeclaration)

Example 13 with EnumConstantDeclaration

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

the class EnumConstantDeclarationTransformationsTest method settingName.

// Name
@Test
public void settingName() {
    EnumConstantDeclaration ecd = consider("A");
    ecd.setName("B");
    assertTransformedToString("B", ecd);
}
Also used : EnumConstantDeclaration(com.github.javaparser.ast.body.EnumConstantDeclaration) Test(org.junit.Test) AbstractLexicalPreservingTest(com.github.javaparser.printer.lexicalpreservation.AbstractLexicalPreservingTest)

Example 14 with EnumConstantDeclaration

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

the class EnumGenerator method addEnumerationValue.

private void addEnumerationValue(EnumLiteralDescr enumLiteral) {
    EnumConstantDeclaration element = new EnumConstantDeclaration(enumLiteral.getName());
    for (String constructorArgument : enumLiteral.getConstructorArgs()) {
        element.addArgument(new NameExpr(constructorArgument));
    }
    enumDeclaration.addEntry(element);
}
Also used : EnumConstantDeclaration(com.github.javaparser.ast.body.EnumConstantDeclaration) NameExpr(com.github.javaparser.ast.expr.NameExpr)

Example 15 with EnumConstantDeclaration

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

the class MaterializedLambda method create.

protected EnumDeclaration create(CompilationUnit compilationUnit) {
    EnumDeclaration lambdaClass = compilationUnit.addEnum(temporaryClassHash);
    lambdaClass.addAnnotation(createSimpleAnnotation(org.drools.compiler.kie.builder.MaterializedLambda.class));
    lambdaClass.setImplementedTypes(createImplementedTypes());
    lambdaClass.addEntry(new EnumConstantDeclaration("INSTANCE"));
    String expressionHash = md5Hash(MATERIALIZED_LAMBDA_PRETTY_PRINTER.print(lambdaExpr));
    String expressionHashFieldName = "EXPRESSION_HASH";
    lambdaClass.addFieldWithInitializer(String.class, expressionHashFieldName, new StringLiteralExpr(expressionHash), Modifier.Keyword.PUBLIC, Modifier.Keyword.STATIC, Modifier.Keyword.FINAL);
    createGetterForExpressionHashField(lambdaClass, expressionHashFieldName);
    return lambdaClass;
}
Also used : EnumConstantDeclaration(com.github.javaparser.ast.body.EnumConstantDeclaration) StringLiteralExpr(com.github.javaparser.ast.expr.StringLiteralExpr) EnumDeclaration(com.github.javaparser.ast.body.EnumDeclaration)

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