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

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

Introduction

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

Prototype

public final void setSourceRange(int startPosition, int length) 

Source Link

Document

Sets the source range of the original source file where the source fragment corresponding to this node was found.

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  w w .j  av  a 2s  .  co  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;
}