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

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

Introduction

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

Prototype

EnumConstantDeclaration(AST ast) 

Source Link

Document

Creates a new AST node for an enumeration constants declaration owned by the given AST.

Usage

From source file:org.eclipse.jdt.core.dom.ASTConverter.java

License:Open Source License

public EnumConstantDeclaration convert(org.eclipse.jdt.internal.compiler.ast.FieldDeclaration enumConstant) {
    checkCanceled();/* w ww  .j a  va2 s.c o m*/
    EnumConstantDeclaration enumConstantDeclaration = new EnumConstantDeclaration(this.ast);
    final SimpleName typeName = new SimpleName(this.ast);
    typeName.internalSetIdentifier(new String(enumConstant.name));
    typeName.setSourceRange(enumConstant.sourceStart, enumConstant.sourceEnd - enumConstant.sourceStart + 1);
    enumConstantDeclaration.setName(typeName);
    int declarationSourceStart = enumConstant.declarationSourceStart;
    int declarationSourceEnd = enumConstant.declarationSourceEnd;
    final org.eclipse.jdt.internal.compiler.ast.Expression initialization = enumConstant.initialization;
    if (initialization != null) {
        if (initialization instanceof QualifiedAllocationExpression) {
            org.eclipse.jdt.internal.compiler.ast.TypeDeclaration anonymousType = ((QualifiedAllocationExpression) initialization).anonymousType;
            if (anonymousType != null) {
                AnonymousClassDeclaration anonymousClassDeclaration = new AnonymousClassDeclaration(this.ast);
                int start = retrieveStartBlockPosition(anonymousType.sourceEnd, anonymousType.bodyEnd);
                int end = retrieveRightBrace(anonymousType.bodyEnd, declarationSourceEnd);
                if (end == -1)
                    end = anonymousType.bodyEnd;
                anonymousClassDeclaration.setSourceRange(start, end - start + 1);
                enumConstantDeclaration.setAnonymousClassDeclaration(anonymousClassDeclaration);
                buildBodyDeclarations(anonymousType, anonymousClassDeclaration);
                if (this.resolveBindings) {
                    recordNodes(anonymousClassDeclaration, anonymousType);
                    anonymousClassDeclaration.resolveBinding();
                }
                enumConstantDeclaration.setSourceRange(declarationSourceStart,
                        end - declarationSourceStart + 1);
            }
        } else {
            enumConstantDeclaration.setSourceRange(declarationSourceStart,
                    declarationSourceEnd - declarationSourceStart + 1);
        }
        final org.eclipse.jdt.internal.compiler.ast.Expression[] arguments = ((org.eclipse.jdt.internal.compiler.ast.AllocationExpression) initialization).arguments;
        if (arguments != null) {
            for (int i = 0, max = arguments.length; i < max; i++) {
                enumConstantDeclaration.arguments().add(convert(arguments[i]));
            }
        }
    } else {
        enumConstantDeclaration.setSourceRange(declarationSourceStart,
                declarationSourceEnd - declarationSourceStart + 1);
    }
    setModifiers(enumConstantDeclaration, enumConstant);
    if (this.resolveBindings) {
        recordNodes(enumConstantDeclaration, enumConstant);
        recordNodes(typeName, enumConstant);
        enumConstantDeclaration.resolveVariable();
    }
    convert(enumConstant.javadoc, enumConstantDeclaration);
    return enumConstantDeclaration;
}