Example usage for org.eclipse.jdt.core.dom EnumConstantDeclaration getParent

List of usage examples for org.eclipse.jdt.core.dom EnumConstantDeclaration getParent

Introduction

In this page you can find the example usage for org.eclipse.jdt.core.dom EnumConstantDeclaration getParent.

Prototype

public final ASTNode getParent() 

Source Link

Document

Returns this node's parent node, or null if this is the root node.

Usage

From source file:com.google.dart.java2dart.SyntaxTranslator.java

License:Open Source License

@Override
public boolean visit(org.eclipse.jdt.core.dom.EnumConstantDeclaration node) {
    String fieldName = node.getName().getIdentifier();
    IMethodBinding constructorBinding = node.resolveConstructorBinding();
    // prepare enum name
    org.eclipse.jdt.core.dom.EnumDeclaration parentEnum = (org.eclipse.jdt.core.dom.EnumDeclaration) node
            .getParent();//from  www .j  a v  a  2s . co m
    String enumTypeName = parentEnum.getName().getIdentifier();
    // may be create Dart top-level class for Java inner class
    String innerClassName = null;
    {
        AnonymousClassDeclaration anoClassDeclaration = node.getAnonymousClassDeclaration();
        if (anoClassDeclaration != null) {
            innerClassName = enumTypeName + "_" + fieldName;
            declareInnerClass(constructorBinding, anoClassDeclaration, innerClassName,
                    new String[] { "String", ENUM_NAME_FIELD_NAME, "int", ENUM_ORDINAL_FIELD_NAME });
        }
    }
    // prepare field type
    TypeName type = typeName(enumTypeName);
    // prepare field variables
    List<VariableDeclaration> variables = Lists.newArrayList();
    {
        List<Expression> argList = translateArguments(null, node.arguments());
        {
            int ordinal = parentEnum.enumConstants().indexOf(node);
            argList.add(0, integer(ordinal));
            argList.add(0, string(fieldName));
        }
        InstanceCreationExpression init;
        if (innerClassName == null) {
            init = instanceCreationExpression(Keyword.NEW, typeName(enumTypeName), argList);
            context.getConstructorDescription(constructorBinding).instanceCreations.add(init);
        } else {
            init = instanceCreationExpression(Keyword.NEW, typeName(innerClassName), argList);
        }
        variables.add(variableDeclaration(fieldName, init));
    }
    return done(fieldDeclaration(translateJavadoc(node), true, Keyword.FINAL, type, variables));
}

From source file:com.kodebeagle.javaparser.TypeResolver.java

License:Apache License

@Override
public boolean visit(org.eclipse.jdt.core.dom.EnumConstantDeclaration node) {
    addBinding(node, node.getName(),//from   w  ww  .j  a v  a 2 s . c o  m
            getFullyQualifiedNameFor(
                    ((org.eclipse.jdt.core.dom.EnumDeclaration) node.getParent()).getName().getIdentifier())
                    + "." + node.getName().getIdentifier());
    return true;
}

From source file:org.spoofax.interpreter.adapter.ecj.ECJFactory.java

License:LGPL

private EnumConstantDeclaration asEnumConstantDeclaration(IStrategoTerm term) {
    EnumConstantDeclaration x = ((WrappedEnumConstantDeclaration) term).getWrappee();
    return x.getParent() == null && x.getAST() == ast ? x
            : (EnumConstantDeclaration) ASTNode.copySubtree(ast, x);
}