Example usage for org.eclipse.jdt.internal.compiler.ast ASTNode IsSecondaryType

List of usage examples for org.eclipse.jdt.internal.compiler.ast ASTNode IsSecondaryType

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.compiler.ast ASTNode IsSecondaryType.

Prototype

int IsSecondaryType

To view the source code for org.eclipse.jdt.internal.compiler.ast ASTNode IsSecondaryType.

Click Source Link

Usage

From source file:org.codehaus.jdt.groovy.internal.compiler.ast.GroovyCompilationUnitDeclaration.java

License:Open Source License

/**
 * Build JDT TypeDeclarations for the groovy type declarations that were parsed from the source file.
 *//* ww w .  j ava2 s. c  o  m*/
private void createTypeDeclarations(ModuleNode moduleNode) {
    List<ClassNode> moduleClassNodes = moduleNode.getClasses();
    List<TypeDeclaration> typeDeclarations = new ArrayList<TypeDeclaration>();
    Map<ClassNode, TypeDeclaration> fromClassNodeToDecl = new HashMap<ClassNode, TypeDeclaration>();

    char[] mainName = toMainName(compilationResult.getFileName());
    boolean isInner = false;
    List<ClassNode> classNodes = null;
    classNodes = moduleClassNodes;
    Map<ClassNode, List<TypeDeclaration>> innersToRecord = new HashMap<ClassNode, List<TypeDeclaration>>();
    for (ClassNode classNode : classNodes) {
        if (!classNode.isPrimaryClassNode()) {
            continue;
        }

        GroovyTypeDeclaration typeDeclaration = new GroovyTypeDeclaration(compilationResult, classNode);

        typeDeclaration.annotations = transformAnnotations(classNode.getAnnotations());
        // FIXASC duplicates code further down, tidy this up
        if (classNode instanceof InnerClassNode) {
            InnerClassNode innerClassNode = (InnerClassNode) classNode;
            ClassNode outerClass = innerClassNode.getOuterClass();
            String outername = outerClass.getNameWithoutPackage();
            String newInner = innerClassNode.getNameWithoutPackage().substring(outername.length() + 1);
            typeDeclaration.name = newInner.toCharArray();
            isInner = true;
        } else {
            typeDeclaration.name = classNode.getNameWithoutPackage().toCharArray();
            isInner = false;
        }

        // classNode.getInnerClasses();
        // classNode.
        boolean isInterface = classNode.isInterface();
        int mods = classNode.getModifiers();
        if ((mods & Opcodes.ACC_ENUM) != 0) {
            // remove final
            mods = mods & ~Opcodes.ACC_FINAL;
        }
        // FIXASC should this modifier be set?
        // mods |= Opcodes.ACC_PUBLIC;
        // FIXASC should not do this for inner classes, just for top level types
        // FIXASC does this make things visible that shouldn't be?
        mods = mods & ~(Opcodes.ACC_PRIVATE | Opcodes.ACC_PROTECTED);
        if (!isInner) {
            if ((mods & Opcodes.ACC_STATIC) != 0) {
                mods = mods & ~(Opcodes.ACC_STATIC);
            }
        }
        typeDeclaration.modifiers = mods & ~(isInterface ? Opcodes.ACC_ABSTRACT : 0);

        if (!(classNode instanceof InnerClassNode)) {
            if (!CharOperation.equals(typeDeclaration.name, mainName)) {
                typeDeclaration.bits |= ASTNode.IsSecondaryType;
            }
        }

        fixupSourceLocationsForTypeDeclaration(typeDeclaration, classNode);

        if (classNode.getGenericsTypes() != null) {
            GenericsType[] genericInfo = classNode.getGenericsTypes();
            // Example case here: Foo<T extends Number & I>
            // the type parameter is T, the 'type' is Number and the bounds for the type parameter are just the extra bound
            // I.
            typeDeclaration.typeParameters = new TypeParameter[genericInfo.length];
            for (int tp = 0; tp < genericInfo.length; tp++) {
                TypeParameter typeParameter = new TypeParameter();
                typeParameter.name = genericInfo[tp].getName().toCharArray();
                ClassNode[] upperBounds = genericInfo[tp].getUpperBounds();
                if (upperBounds != null) {
                    // FIXASC (M3) Positional info for these references?
                    typeParameter.type = createTypeReferenceForClassNode(upperBounds[0]);
                    typeParameter.bounds = (upperBounds.length > 1 ? new TypeReference[upperBounds.length - 1]
                            : null);
                    for (int b = 1, max = upperBounds.length; b < max; b++) {
                        typeParameter.bounds[b - 1] = createTypeReferenceForClassNode(upperBounds[b]);
                        typeParameter.bounds[b - 1].bits |= ASTNode.IsSuperType;
                    }
                }
                typeDeclaration.typeParameters[tp] = typeParameter;
            }
        }

        boolean isEnum = (classNode.getModifiers() & Opcodes.ACC_ENUM) != 0;
        configureSuperClass(typeDeclaration, classNode.getSuperClass(), isEnum);
        configureSuperInterfaces(typeDeclaration, classNode);
        typeDeclaration.methods = createMethodAndConstructorDeclarations(classNode, isEnum, compilationResult);
        typeDeclaration.fields = createFieldDeclarations(classNode);
        typeDeclaration.properties = classNode.getProperties();
        if (classNode instanceof InnerClassNode) {
            InnerClassNode innerClassNode = (InnerClassNode) classNode;
            ClassNode outerClass = innerClassNode.getOuterClass();
            String outername = outerClass.getNameWithoutPackage();
            String newInner = innerClassNode.getNameWithoutPackage().substring(outername.length() + 1);
            typeDeclaration.name = newInner.toCharArray();

            // Record that we need to set the parent of this inner type later
            List<TypeDeclaration> inners = innersToRecord.get(outerClass);
            if (inners == null) {
                inners = new ArrayList<TypeDeclaration>();
                innersToRecord.put(outerClass, inners);
            }
            inners.add(typeDeclaration);
        } else {
            typeDeclarations.add(typeDeclaration);
        }
        fromClassNodeToDecl.put(classNode, typeDeclaration);
    }

    // For inner types, now attach them to their parents. This was not done earlier as sometimes the types are processed in
    // such an order that inners are dealt with before outers
    for (Map.Entry<ClassNode, List<TypeDeclaration>> innersToRecordEntry : innersToRecord.entrySet()) {
        TypeDeclaration outerTypeDeclaration = fromClassNodeToDecl.get(innersToRecordEntry.getKey());
        // Check if there is a problem locating the parent for the inner
        if (outerTypeDeclaration == null) {
            throw new GroovyEclipseBug(
                    "Failed to find the type declaration for " + innersToRecordEntry.getKey().getName());
        }
        List<TypeDeclaration> newInnersList = innersToRecordEntry.getValue();
        outerTypeDeclaration.memberTypes = newInnersList.toArray(new TypeDeclaration[newInnersList.size()]);
    }

    types = typeDeclarations.toArray(new TypeDeclaration[typeDeclarations.size()]);
}

From source file:org.eclipse.jdt.internal.compiler.parser.Parser.java

License:Open Source License

protected void consumeAnnotationTypeDeclarationHeaderName() {
    // consumeAnnotationTypeDeclarationHeader ::= Modifiers '@' PushModifiers interface Identifier
    // consumeAnnotationTypeDeclarationHeader ::= '@' PushModifiers interface Identifier
    TypeDeclaration annotationTypeDeclaration = new TypeDeclaration(this.compilationUnit.compilationResult);
    if (this.nestedMethod[this.nestedType] == 0) {
        if (this.nestedType != 0) {
            annotationTypeDeclaration.bits |= ASTNode.IsMemberType;
        }//from w  ww  .  j  ava  2 s.  c om
    } else {
        // Record that the block has a declaration for local types
        annotationTypeDeclaration.bits |= ASTNode.IsLocalType;
        markEnclosingMemberWithLocalType();
        blockReal();
    }

    //highlight the name of the type
    long pos = this.identifierPositionStack[this.identifierPtr];
    annotationTypeDeclaration.sourceEnd = (int) pos;
    annotationTypeDeclaration.sourceStart = (int) (pos >>> 32);
    annotationTypeDeclaration.name = this.identifierStack[this.identifierPtr--];
    this.identifierLengthPtr--;

    //compute the declaration source too
    // 'interface' push two int positions: the beginning of the class token and its end.
    // we want to keep the beginning position but get rid of the end position
    // it is only used for the ClassLiteralAccess positions.
    this.intPtr--; // remove the start position of the interface token
    this.intPtr--; // remove the end position of the interface token

    annotationTypeDeclaration.modifiersSourceStart = this.intStack[this.intPtr--];
    annotationTypeDeclaration.modifiers = this.intStack[this.intPtr--] | ClassFileConstants.AccAnnotation
            | ClassFileConstants.AccInterface;
    if (annotationTypeDeclaration.modifiersSourceStart >= 0) {
        annotationTypeDeclaration.declarationSourceStart = annotationTypeDeclaration.modifiersSourceStart;
        this.intPtr--; // remove the position of the '@' token as we have modifiers
    } else {
        int atPosition = this.intStack[this.intPtr--];
        // remove the position of the '@' token as we don't have modifiers
        annotationTypeDeclaration.declarationSourceStart = atPosition;
    }

    // Store secondary info
    if ((annotationTypeDeclaration.bits & ASTNode.IsMemberType) == 0
            && (annotationTypeDeclaration.bits & ASTNode.IsLocalType) == 0) {
        if (this.compilationUnit != null && !CharOperation.equals(annotationTypeDeclaration.name,
                this.compilationUnit.getMainTypeName())) {
            annotationTypeDeclaration.bits |= ASTNode.IsSecondaryType;
        }
    }

    // consume annotations
    int length;
    if ((length = this.expressionLengthStack[this.expressionLengthPtr--]) != 0) {
        System.arraycopy(this.expressionStack, (this.expressionPtr -= length) + 1,
                annotationTypeDeclaration.annotations = new Annotation[length], 0, length);
    }
    annotationTypeDeclaration.bodyStart = annotationTypeDeclaration.sourceEnd + 1;

    // javadoc
    annotationTypeDeclaration.javadoc = this.javadoc;
    this.javadoc = null;
    pushOnAstStack(annotationTypeDeclaration);
    if (!this.statementRecoveryActivated && this.options.sourceLevel < ClassFileConstants.JDK1_5
            && this.lastErrorEndPositionBeforeRecovery < this.scanner.currentPosition) {
        problemReporter().invalidUsageOfAnnotationDeclarations(annotationTypeDeclaration);
    }

    // recovery
    if (this.currentElement != null) {
        this.lastCheckPoint = annotationTypeDeclaration.bodyStart;
        this.currentElement = this.currentElement.add(annotationTypeDeclaration, 0);
        this.lastIgnoredToken = -1;
    }
}

From source file:org.eclipse.jdt.internal.compiler.parser.Parser.java

License:Open Source License

protected void consumeAnnotationTypeDeclarationHeaderNameWithTypeParameters() {
    // consumeAnnotationTypeDeclarationHeader ::= Modifiers '@' PushModifiers interface Identifier TypeParameters
    // consumeAnnotationTypeDeclarationHeader ::= '@' PushModifiers interface Identifier TypeParameters
    TypeDeclaration annotationTypeDeclaration = new TypeDeclaration(this.compilationUnit.compilationResult);
    // consume type parameters
    int length = this.genericsLengthStack[this.genericsLengthPtr--];
    this.genericsPtr -= length;
    System.arraycopy(this.genericsStack, this.genericsPtr + 1,
            annotationTypeDeclaration.typeParameters = new TypeParameter[length], 0, length);

    problemReporter().invalidUsageOfTypeParametersForAnnotationDeclaration(annotationTypeDeclaration);

    annotationTypeDeclaration.bodyStart = annotationTypeDeclaration.typeParameters[length
            - 1].declarationSourceEnd + 1;

    //   annotationTypeDeclaration.typeParameters = null;

    this.listTypeParameterLength = 0;

    if (this.nestedMethod[this.nestedType] == 0) {
        if (this.nestedType != 0) {
            annotationTypeDeclaration.bits |= ASTNode.IsMemberType;
        }/* ww  w  . j  av  a 2s  . c  o  m*/
    } else {
        // Record that the block has a declaration for local types
        annotationTypeDeclaration.bits |= ASTNode.IsLocalType;
        markEnclosingMemberWithLocalType();
        blockReal();
    }

    //highlight the name of the type
    long pos = this.identifierPositionStack[this.identifierPtr];
    annotationTypeDeclaration.sourceEnd = (int) pos;
    annotationTypeDeclaration.sourceStart = (int) (pos >>> 32);
    annotationTypeDeclaration.name = this.identifierStack[this.identifierPtr--];
    this.identifierLengthPtr--;

    //compute the declaration source too
    // 'interface' push two int positions: the beginning of the class token and its end.
    // we want to keep the beginning position but get rid of the end position
    // it is only used for the ClassLiteralAccess positions.
    this.intPtr--; // remove the start position of the interface token
    this.intPtr--; // remove the end position of the interface token

    annotationTypeDeclaration.modifiersSourceStart = this.intStack[this.intPtr--];
    annotationTypeDeclaration.modifiers = this.intStack[this.intPtr--] | ClassFileConstants.AccAnnotation
            | ClassFileConstants.AccInterface;
    if (annotationTypeDeclaration.modifiersSourceStart >= 0) {
        annotationTypeDeclaration.declarationSourceStart = annotationTypeDeclaration.modifiersSourceStart;
        this.intPtr--; // remove the position of the '@' token as we have modifiers
    } else {
        int atPosition = this.intStack[this.intPtr--];
        // remove the position of the '@' token as we don't have modifiers
        annotationTypeDeclaration.declarationSourceStart = atPosition;
    }

    // Store secondary info
    if ((annotationTypeDeclaration.bits & ASTNode.IsMemberType) == 0
            && (annotationTypeDeclaration.bits & ASTNode.IsLocalType) == 0) {
        if (this.compilationUnit != null && !CharOperation.equals(annotationTypeDeclaration.name,
                this.compilationUnit.getMainTypeName())) {
            annotationTypeDeclaration.bits |= ASTNode.IsSecondaryType;
        }
    }

    // consume annotations
    if ((length = this.expressionLengthStack[this.expressionLengthPtr--]) != 0) {
        System.arraycopy(this.expressionStack, (this.expressionPtr -= length) + 1,
                annotationTypeDeclaration.annotations = new Annotation[length], 0, length);
    }
    // javadoc
    annotationTypeDeclaration.javadoc = this.javadoc;
    this.javadoc = null;
    pushOnAstStack(annotationTypeDeclaration);
    if (!this.statementRecoveryActivated && this.options.sourceLevel < ClassFileConstants.JDK1_5
            && this.lastErrorEndPositionBeforeRecovery < this.scanner.currentPosition) {
        problemReporter().invalidUsageOfAnnotationDeclarations(annotationTypeDeclaration);
    }

    // recovery
    if (this.currentElement != null) {
        this.lastCheckPoint = annotationTypeDeclaration.bodyStart;
        this.currentElement = this.currentElement.add(annotationTypeDeclaration, 0);
        this.lastIgnoredToken = -1;
    }
}

From source file:org.eclipse.jdt.internal.compiler.parser.Parser.java

License:Open Source License

protected void consumeClassHeaderName1() {
    // ClassHeaderName1 ::= Modifiersopt 'class' 'Identifier'
    TypeDeclaration typeDecl = new TypeDeclaration(this.compilationUnit.compilationResult);
    if (this.nestedMethod[this.nestedType] == 0) {
        if (this.nestedType != 0) {
            typeDecl.bits |= ASTNode.IsMemberType;
        }//from  w w  w.jav  a 2s.  c o m
    } else {
        // Record that the block has a declaration for local types
        typeDecl.bits |= ASTNode.IsLocalType;
        markEnclosingMemberWithLocalType();
        blockReal();
    }

    //highlight the name of the type
    long pos = this.identifierPositionStack[this.identifierPtr];
    typeDecl.sourceEnd = (int) pos;
    typeDecl.sourceStart = (int) (pos >>> 32);
    typeDecl.name = this.identifierStack[this.identifierPtr--];
    this.identifierLengthPtr--;

    //compute the declaration source too
    // 'class' and 'interface' push two int positions: the beginning of the class token and its end.
    // we want to keep the beginning position but get rid of the end position
    // it is only used for the ClassLiteralAccess positions.
    typeDecl.declarationSourceStart = this.intStack[this.intPtr--];
    this.intPtr--; // remove the end position of the class token

    typeDecl.modifiersSourceStart = this.intStack[this.intPtr--];
    typeDecl.modifiers = this.intStack[this.intPtr--];
    if (typeDecl.modifiersSourceStart >= 0) {
        typeDecl.declarationSourceStart = typeDecl.modifiersSourceStart;
    }

    // Store secondary info
    if ((typeDecl.bits & ASTNode.IsMemberType) == 0 && (typeDecl.bits & ASTNode.IsLocalType) == 0) {
        if (this.compilationUnit != null
                && !CharOperation.equals(typeDecl.name, this.compilationUnit.getMainTypeName())) {
            typeDecl.bits |= ASTNode.IsSecondaryType;
        }
    }

    // consume annotations
    int length;
    if ((length = this.expressionLengthStack[this.expressionLengthPtr--]) != 0) {
        System.arraycopy(this.expressionStack, (this.expressionPtr -= length) + 1,
                typeDecl.annotations = new Annotation[length], 0, length);
    }
    typeDecl.bodyStart = typeDecl.sourceEnd + 1;
    pushOnAstStack(typeDecl);

    this.listLength = 0; // will be updated when reading super-interfaces
    // recovery
    if (this.currentElement != null) {
        this.lastCheckPoint = typeDecl.bodyStart;
        this.currentElement = this.currentElement.add(typeDecl, 0);
        this.lastIgnoredToken = -1;
    }
    // javadoc
    typeDecl.javadoc = this.javadoc;
    this.javadoc = null;
}

From source file:org.eclipse.jdt.internal.compiler.parser.Parser.java

License:Open Source License

protected void consumeEnumHeaderName() {
    // EnumHeaderName ::= Modifiersopt 'enum' Identifier
    TypeDeclaration enumDeclaration = new TypeDeclaration(this.compilationUnit.compilationResult);
    if (this.nestedMethod[this.nestedType] == 0) {
        if (this.nestedType != 0) {
            enumDeclaration.bits |= ASTNode.IsMemberType;
        }/*from  w w  w.ja v  a  2  s  . c  om*/
    } else {
        // Record that the block has a declaration for local types
        //      markEnclosingMemberWithLocalType();
        blockReal();
    }
    //highlight the name of the type
    long pos = this.identifierPositionStack[this.identifierPtr];
    enumDeclaration.sourceEnd = (int) pos;
    enumDeclaration.sourceStart = (int) (pos >>> 32);
    enumDeclaration.name = this.identifierStack[this.identifierPtr--];
    this.identifierLengthPtr--;

    //compute the declaration source too
    // 'class' and 'interface' push two int positions: the beginning of the class token and its end.
    // we want to keep the beginning position but get rid of the end position
    // it is only used for the ClassLiteralAccess positions.
    enumDeclaration.declarationSourceStart = this.intStack[this.intPtr--];
    this.intPtr--; // remove the end position of the class token

    enumDeclaration.modifiersSourceStart = this.intStack[this.intPtr--];
    enumDeclaration.modifiers = this.intStack[this.intPtr--] | ClassFileConstants.AccEnum;
    if (enumDeclaration.modifiersSourceStart >= 0) {
        enumDeclaration.declarationSourceStart = enumDeclaration.modifiersSourceStart;
    }

    // Store secondary info
    if ((enumDeclaration.bits & ASTNode.IsMemberType) == 0
            && (enumDeclaration.bits & ASTNode.IsLocalType) == 0) {
        if (this.compilationUnit != null
                && !CharOperation.equals(enumDeclaration.name, this.compilationUnit.getMainTypeName())) {
            enumDeclaration.bits |= ASTNode.IsSecondaryType;
        }
    }

    // consume annotations
    int length;
    if ((length = this.expressionLengthStack[this.expressionLengthPtr--]) != 0) {
        System.arraycopy(this.expressionStack, (this.expressionPtr -= length) + 1,
                enumDeclaration.annotations = new Annotation[length], 0, length);
    }
    //   if (this.currentToken == TokenNameLBRACE) {
    //      enumDeclaration.bodyStart = this.scanner.currentPosition;
    //   }
    enumDeclaration.bodyStart = enumDeclaration.sourceEnd + 1;
    pushOnAstStack(enumDeclaration);

    this.listLength = 0; // will be updated when reading super-interfaces

    if (!this.statementRecoveryActivated && this.options.sourceLevel < ClassFileConstants.JDK1_5
            && this.lastErrorEndPositionBeforeRecovery < this.scanner.currentPosition) {
        //TODO this code will be never run while 'enum' is an identifier in 1.3 scanner
        problemReporter().invalidUsageOfEnumDeclarations(enumDeclaration);
    }

    // recovery
    if (this.currentElement != null) {
        this.lastCheckPoint = enumDeclaration.bodyStart;
        this.currentElement = this.currentElement.add(enumDeclaration, 0);
        this.lastIgnoredToken = -1;
    }
    // javadoc
    enumDeclaration.javadoc = this.javadoc;
    this.javadoc = null;
}

From source file:org.eclipse.jdt.internal.compiler.parser.Parser.java

License:Open Source License

protected void consumeEnumHeaderNameWithTypeParameters() {
    // EnumHeaderNameWithTypeParameters ::= Modifiersopt 'enum' Identifier TypeParameters
    TypeDeclaration enumDeclaration = new TypeDeclaration(this.compilationUnit.compilationResult);
    // consume type parameters
    int length = this.genericsLengthStack[this.genericsLengthPtr--];
    this.genericsPtr -= length;
    System.arraycopy(this.genericsStack, this.genericsPtr + 1,
            enumDeclaration.typeParameters = new TypeParameter[length], 0, length);

    problemReporter().invalidUsageOfTypeParametersForEnumDeclaration(enumDeclaration);

    enumDeclaration.bodyStart = enumDeclaration.typeParameters[length - 1].declarationSourceEnd + 1;

    //   enumDeclaration.typeParameters = null;

    this.listTypeParameterLength = 0;

    if (this.nestedMethod[this.nestedType] == 0) {
        if (this.nestedType != 0) {
            enumDeclaration.bits |= ASTNode.IsMemberType;
        }/*www .j  a  va2s.co  m*/
    } else {
        // Record that the block has a declaration for local types
        //      markEnclosingMemberWithLocalType();
        blockReal();
    }
    //highlight the name of the type
    long pos = this.identifierPositionStack[this.identifierPtr];
    enumDeclaration.sourceEnd = (int) pos;
    enumDeclaration.sourceStart = (int) (pos >>> 32);
    enumDeclaration.name = this.identifierStack[this.identifierPtr--];
    this.identifierLengthPtr--;

    //compute the declaration source too
    // 'class' and 'interface' push two int positions: the beginning of the class token and its end.
    // we want to keep the beginning position but get rid of the end position
    // it is only used for the ClassLiteralAccess positions.
    enumDeclaration.declarationSourceStart = this.intStack[this.intPtr--];
    this.intPtr--; // remove the end position of the class token

    enumDeclaration.modifiersSourceStart = this.intStack[this.intPtr--];
    enumDeclaration.modifiers = this.intStack[this.intPtr--] | ClassFileConstants.AccEnum;
    if (enumDeclaration.modifiersSourceStart >= 0) {
        enumDeclaration.declarationSourceStart = enumDeclaration.modifiersSourceStart;
    }

    // Store secondary info
    if ((enumDeclaration.bits & ASTNode.IsMemberType) == 0
            && (enumDeclaration.bits & ASTNode.IsLocalType) == 0) {
        if (this.compilationUnit != null
                && !CharOperation.equals(enumDeclaration.name, this.compilationUnit.getMainTypeName())) {
            enumDeclaration.bits |= ASTNode.IsSecondaryType;
        }
    }

    // consume annotations
    if ((length = this.expressionLengthStack[this.expressionLengthPtr--]) != 0) {
        System.arraycopy(this.expressionStack, (this.expressionPtr -= length) + 1,
                enumDeclaration.annotations = new Annotation[length], 0, length);
    }
    //   if (this.currentToken == TokenNameLBRACE) {
    //      enumDeclaration.bodyStart = this.scanner.currentPosition;
    //   }
    enumDeclaration.bodyStart = enumDeclaration.sourceEnd + 1;
    pushOnAstStack(enumDeclaration);

    this.listLength = 0; // will be updated when reading super-interfaces

    if (!this.statementRecoveryActivated && this.options.sourceLevel < ClassFileConstants.JDK1_5
            && this.lastErrorEndPositionBeforeRecovery < this.scanner.currentPosition) {
        //TODO this code will be never run while 'enum' is an identifier in 1.3 scanner
        problemReporter().invalidUsageOfEnumDeclarations(enumDeclaration);
    }

    // recovery
    if (this.currentElement != null) {
        this.lastCheckPoint = enumDeclaration.bodyStart;
        this.currentElement = this.currentElement.add(enumDeclaration, 0);
        this.lastIgnoredToken = -1;
    }
    // javadoc
    enumDeclaration.javadoc = this.javadoc;
    this.javadoc = null;
}

From source file:org.eclipse.jdt.internal.compiler.parser.Parser.java

License:Open Source License

protected void consumeInterfaceHeaderName1() {
    // InterfaceHeaderName ::= Modifiersopt 'interface' 'Identifier'
    TypeDeclaration typeDecl = new TypeDeclaration(this.compilationUnit.compilationResult);

    if (this.nestedMethod[this.nestedType] == 0) {
        if (this.nestedType != 0) {
            typeDecl.bits |= ASTNode.IsMemberType;
        }//ww w  . ja v  a2 s.c  o  m
    } else {
        // Record that the block has a declaration for local types
        typeDecl.bits |= ASTNode.IsLocalType;
        markEnclosingMemberWithLocalType();
        blockReal();
    }

    //highlight the name of the type
    long pos = this.identifierPositionStack[this.identifierPtr];
    typeDecl.sourceEnd = (int) pos;
    typeDecl.sourceStart = (int) (pos >>> 32);
    typeDecl.name = this.identifierStack[this.identifierPtr--];
    this.identifierLengthPtr--;

    //compute the declaration source too
    // 'class' and 'interface' push two int positions: the beginning of the class token and its end.
    // we want to keep the beginning position but get rid of the end position
    // it is only used for the ClassLiteralAccess positions.
    typeDecl.declarationSourceStart = this.intStack[this.intPtr--];
    this.intPtr--; // remove the end position of the class token
    typeDecl.modifiersSourceStart = this.intStack[this.intPtr--];
    typeDecl.modifiers = this.intStack[this.intPtr--] | ClassFileConstants.AccInterface;
    if (typeDecl.modifiersSourceStart >= 0) {
        typeDecl.declarationSourceStart = typeDecl.modifiersSourceStart;
    }

    // Store secondary info
    if ((typeDecl.bits & ASTNode.IsMemberType) == 0 && (typeDecl.bits & ASTNode.IsLocalType) == 0) {
        if (this.compilationUnit != null
                && !CharOperation.equals(typeDecl.name, this.compilationUnit.getMainTypeName())) {
            typeDecl.bits |= ASTNode.IsSecondaryType;
        }
    }

    // consume annotations
    int length;
    if ((length = this.expressionLengthStack[this.expressionLengthPtr--]) != 0) {
        System.arraycopy(this.expressionStack, (this.expressionPtr -= length) + 1,
                typeDecl.annotations = new Annotation[length], 0, length);
    }
    typeDecl.bodyStart = typeDecl.sourceEnd + 1;
    pushOnAstStack(typeDecl);
    this.listLength = 0; // will be updated when reading super-interfaces
    // recovery
    if (this.currentElement != null) { // is recovering
        this.lastCheckPoint = typeDecl.bodyStart;
        this.currentElement = this.currentElement.add(typeDecl, 0);
        this.lastIgnoredToken = -1;
    }
    // javadoc
    typeDecl.javadoc = this.javadoc;
    this.javadoc = null;
}