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

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

Introduction

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

Prototype

EnumDeclaration(AST ast) 

Source Link

Document

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

Usage

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

License:Open Source License

private EnumDeclaration convertToEnumDeclaration(
        org.eclipse.jdt.internal.compiler.ast.TypeDeclaration typeDeclaration) {
    checkCanceled();/*from w  w w. j  a  v a2 s. c  o  m*/
    // enum declaration cannot be built if the source is not >= 1.5, since enum is then seen as an identifier
    final EnumDeclaration enumDeclaration2 = new EnumDeclaration(this.ast);
    setModifiers(enumDeclaration2, typeDeclaration);
    final SimpleName typeName = new SimpleName(this.ast);
    typeName.internalSetIdentifier(new String(typeDeclaration.name));
    typeName.setSourceRange(typeDeclaration.sourceStart,
            typeDeclaration.sourceEnd - typeDeclaration.sourceStart + 1);
    enumDeclaration2.setName(typeName);
    enumDeclaration2.setSourceRange(typeDeclaration.declarationSourceStart,
            typeDeclaration.bodyEnd - typeDeclaration.declarationSourceStart + 1);

    org.eclipse.jdt.internal.compiler.ast.TypeReference[] superInterfaces = typeDeclaration.superInterfaces;
    if (superInterfaces != null) {
        for (int index = 0, length = superInterfaces.length; index < length; index++) {
            enumDeclaration2.superInterfaceTypes().add(convertType(superInterfaces[index]));
        }
    }
    buildBodyDeclarations(typeDeclaration, enumDeclaration2);
    if (this.resolveBindings) {
        recordNodes(enumDeclaration2, typeDeclaration);
        recordNodes(typeName, typeDeclaration);
        enumDeclaration2.resolveBinding();
    }
    return enumDeclaration2;
}