Example usage for org.eclipse.jdt.internal.compiler.ast AbstractVariableDeclaration ENUM_CONSTANT

List of usage examples for org.eclipse.jdt.internal.compiler.ast AbstractVariableDeclaration ENUM_CONSTANT

Introduction

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

Prototype

int ENUM_CONSTANT

To view the source code for org.eclipse.jdt.internal.compiler.ast AbstractVariableDeclaration ENUM_CONSTANT.

Click Source Link

Usage

From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.FieldLocator.java

License:Open Source License

public int match(FieldDeclaration node, MatchingNodeSet nodeSet) {
    int referencesLevel = IMPOSSIBLE_MATCH;
    if (this.pattern.findReferences)
        // must be a write only access with an initializer
        if (this.pattern.writeAccess && !this.pattern.readAccess && node.initialization != null)
            if (matchesName(this.pattern.name, node.name))
                referencesLevel = this.pattern.mustResolve ? POSSIBLE_MATCH : ACCURATE_MATCH;

    int declarationsLevel = IMPOSSIBLE_MATCH;
    if (this.pattern.findDeclarations) {
        switch (node.getKind()) {
        case AbstractVariableDeclaration.FIELD:
        case AbstractVariableDeclaration.ENUM_CONSTANT:
            if (matchesName(this.pattern.name, node.name))
                if (matchesTypeReference(((FieldPattern) this.pattern).typeSimpleName, node.type))
                    declarationsLevel = this.pattern.mustResolve ? POSSIBLE_MATCH : ACCURATE_MATCH;
            break;
        }//from w  w  w  .j  av  a 2s . c o  m
    }
    return nodeSet.addMatch(node, referencesLevel >= declarationsLevel ? referencesLevel : declarationsLevel); // use the stronger match
}

From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.MatchLocator.java

License:Open Source License

/**
 * Creates an IField from the given field declaration and type.
 *//*from  www  .  java 2  s . c  o  m*/
protected IJavaElement createHandle(FieldDeclaration fieldDeclaration, TypeDeclaration typeDeclaration,
        IJavaElement parent) {
    if (!(parent instanceof IType))
        return parent;
    IType type = (IType) parent;

    switch (fieldDeclaration.getKind()) {
    case AbstractVariableDeclaration.FIELD:
    case AbstractVariableDeclaration.ENUM_CONSTANT:
        return ((IType) parent).getField(new String(fieldDeclaration.name));
    }
    if (type.isBinary()) {
        // do not return initializer for binary types
        // see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=98378
        return type;
    }
    // find occurrence count of the given initializer in its type declaration
    int occurrenceCount = 0;
    FieldDeclaration[] fields = typeDeclaration.fields;
    int length = fields == null ? 0 : fields.length;
    for (int i = 0; i < length; i++) {
        if (fields[i].getKind() == AbstractVariableDeclaration.INITIALIZER) {
            occurrenceCount++;
            if (fields[i].equals(fieldDeclaration))
                break;
        }
    }
    return ((IType) parent).getInitializer(occurrenceCount);
}

From source file:com.codenvy.ide.ext.java.server.internal.core.util.HandleFactory.java

License:Open Source License

/**
 * Create handle by adding child to parent obtained by recursing into parent scopes.
 *///from www .java 2s . c  o m
private IJavaElement createElement(Scope scope, int elementPosition, ICompilationUnit unit,
        HashSet existingElements, HashMap knownScopes) {
    IJavaElement newElement = (IJavaElement) knownScopes.get(scope);
    if (newElement != null)
        return newElement;

    switch (scope.kind) {
    case Scope.COMPILATION_UNIT_SCOPE:
        newElement = unit;
        break;
    case Scope.CLASS_SCOPE:
        IJavaElement parentElement = createElement(scope.parent, elementPosition, unit, existingElements,
                knownScopes);
        switch (parentElement.getElementType()) {
        case IJavaElement.COMPILATION_UNIT:
            newElement = ((ICompilationUnit) parentElement)
                    .getType(new String(scope.enclosingSourceType().sourceName));
            break;
        case IJavaElement.TYPE:
            newElement = ((IType) parentElement).getType(new String(scope.enclosingSourceType().sourceName));
            break;
        case IJavaElement.FIELD:
        case IJavaElement.INITIALIZER:
        case IJavaElement.METHOD:
            IMember member = (IMember) parentElement;
            if (member.isBinary()) {
                return null;
            } else {
                newElement = member.getType(new String(scope.enclosingSourceType().sourceName), 1);
                // increment occurrence count if collision is detected
                if (newElement != null) {
                    while (!existingElements.add(newElement))
                        ((SourceRefElement) newElement).occurrenceCount++;
                }
            }
            break;
        }
        if (newElement != null) {
            knownScopes.put(scope, newElement);
        }
        break;
    case Scope.METHOD_SCOPE:
        IType parentType = (IType) createElement(scope.parent, elementPosition, unit, existingElements,
                knownScopes);
        MethodScope methodScope = (MethodScope) scope;
        if (methodScope.isInsideInitializer()) {
            // inside field or initializer, must find proper one
            TypeDeclaration type = methodScope.referenceType();
            int occurenceCount = 1;
            int length = type.fields == null ? 0 : type.fields.length;
            for (int i = 0; i < length; i++) {
                FieldDeclaration field = type.fields[i];
                if (field.declarationSourceStart <= elementPosition
                        && elementPosition <= field.declarationSourceEnd) {
                    switch (field.getKind()) {
                    case AbstractVariableDeclaration.FIELD:
                    case AbstractVariableDeclaration.ENUM_CONSTANT:
                        newElement = parentType.getField(new String(field.name));
                        break;
                    case AbstractVariableDeclaration.INITIALIZER:
                        newElement = parentType.getInitializer(occurenceCount);
                        break;
                    }
                    break;
                } else if (field.getKind() == AbstractVariableDeclaration.INITIALIZER) {
                    occurenceCount++;
                }
            }
        } else {
            // method element
            AbstractMethodDeclaration method = methodScope.referenceMethod();
            newElement = parentType.getMethod(new String(method.selector),
                    Util.typeParameterSignatures(method));
            if (newElement != null) {
                knownScopes.put(scope, newElement);
            }
        }
        break;
    case Scope.BLOCK_SCOPE:
        // standard block, no element per se
        newElement = createElement(scope.parent, elementPosition, unit, existingElements, knownScopes);
        break;
    }
    return newElement;
}

From source file:org.eclipse.ajdt.core.parserbridge.AJSourceElementNotifier.java

License:Open Source License

protected void notifySourceElementRequestor(FieldDeclaration fieldDeclaration, TypeDeclaration declaringType) {

    // range check
    boolean isInRange = initialPosition <= fieldDeclaration.declarationSourceStart
            && eofPosition >= fieldDeclaration.declarationSourceEnd;

    switch (fieldDeclaration.getKind()) {
    case AbstractVariableDeclaration.ENUM_CONSTANT:
        if (this.reportReferenceInfo) {
            // accept constructor reference for enum constant
            if (fieldDeclaration.initialization instanceof AllocationExpression) {
                AllocationExpression alloc = (AllocationExpression) fieldDeclaration.initialization;
                requestor.acceptConstructorReference(declaringType.name,
                        alloc.arguments == null ? 0 : alloc.arguments.length, alloc.sourceStart);
            }/* w ww  .j  ava 2  s  . co m*/
        }
        // fall through next case
    case AbstractVariableDeclaration.FIELD:
        int fieldEndPosition = this.sourceEnds.get(fieldDeclaration);
        if (fieldEndPosition == -1) {
            // use the declaration source end by default
            fieldEndPosition = fieldDeclaration.declarationSourceEnd;
        }
        if (isInRange) {
            int currentModifiers = fieldDeclaration.modifiers;

            // remember deprecation so as to not lose it below
            boolean deprecated = (currentModifiers & ClassFileConstants.AccDeprecated) != 0
                    || hasDeprecatedAnnotation(fieldDeclaration.annotations);

            char[] typeName = null;
            if (fieldDeclaration.type == null) {
                // enum constant
                typeName = declaringType.name;
                currentModifiers |= ClassFileConstants.AccEnum;
            } else {
                // regular field
                typeName = CharOperation.concatWith(fieldDeclaration.type.getParameterizedTypeName(), '.');
            }
            ISourceElementRequestor.FieldInfo fieldInfo = new ISourceElementRequestor.FieldInfo();
            fieldInfo.declarationStart = fieldDeclaration.declarationSourceStart;
            fieldInfo.name = fieldDeclaration.name;
            fieldInfo.modifiers = deprecated
                    ? (currentModifiers & ExtraCompilerModifiers.AccJustFlag) | ClassFileConstants.AccDeprecated
                    : currentModifiers & ExtraCompilerModifiers.AccJustFlag;
            fieldInfo.type = typeName;
            fieldInfo.nameSourceStart = fieldDeclaration.sourceStart;
            fieldInfo.nameSourceEnd = fieldDeclaration.sourceEnd;
            fieldInfo.categories = (char[][]) this.nodesToCategories.get(fieldDeclaration);
            fieldInfo.annotations = fieldDeclaration.annotations;
            fieldInfo.node = fieldDeclaration;
            requestor.enterField(fieldInfo);
        }
        this.visitIfNeeded(fieldDeclaration, declaringType);
        if (isInRange) {
            requestor.exitField(
                    // filter out initializations that are not a constant (simple check)
                    (fieldDeclaration.initialization == null
                            || fieldDeclaration.initialization instanceof ArrayInitializer
                            || fieldDeclaration.initialization instanceof AllocationExpression
                            || fieldDeclaration.initialization instanceof ArrayAllocationExpression
                            || fieldDeclaration.initialization instanceof Assignment
                            || fieldDeclaration.initialization instanceof ClassLiteralAccess
                            || fieldDeclaration.initialization instanceof MessageSend
                            || fieldDeclaration.initialization instanceof ArrayReference
                            || fieldDeclaration.initialization instanceof ThisReference) ? -1
                                    : fieldDeclaration.initialization.sourceStart,
                    fieldEndPosition, fieldDeclaration.declarationSourceEnd);
        }
        break;
    case AbstractVariableDeclaration.INITIALIZER:
        if (isInRange) {
            requestor.enterInitializer(fieldDeclaration.declarationSourceStart, fieldDeclaration.modifiers);
        }
        this.visitIfNeeded((Initializer) fieldDeclaration);
        if (isInRange) {
            requestor.exitInitializer(fieldDeclaration.declarationSourceEnd);
        }
        break;
    }
}

From source file:org.eclipse.che.jdt.internal.core.util.HandleFactory.java

License:Open Source License

/**
 * Create handle by adding child to parent obtained by recursing into parent scopes.
 *///from ww w.ja v a  2 s .  c o m
public IJavaElement createElement(Scope scope, int elementPosition, ICompilationUnit unit,
        HashSet existingElements, HashMap knownScopes) {
    IJavaElement newElement = (IJavaElement) knownScopes.get(scope);
    if (newElement != null)
        return newElement;

    switch (scope.kind) {
    case Scope.COMPILATION_UNIT_SCOPE:
        newElement = unit;
        break;
    case Scope.CLASS_SCOPE:
        IJavaElement parentElement = createElement(scope.parent, elementPosition, unit, existingElements,
                knownScopes);
        switch (parentElement.getElementType()) {
        case IJavaElement.COMPILATION_UNIT:
            newElement = ((ICompilationUnit) parentElement)
                    .getType(new String(scope.enclosingSourceType().sourceName));
            break;
        case IJavaElement.TYPE:
            newElement = ((IType) parentElement).getType(new String(scope.enclosingSourceType().sourceName));
            break;
        case IJavaElement.FIELD:
        case IJavaElement.INITIALIZER:
        case IJavaElement.METHOD:
            IMember member = (IMember) parentElement;
            if (member.isBinary()) {
                return null;
            } else {
                newElement = member.getType(new String(scope.enclosingSourceType().sourceName), 1);
                // increment occurrence count if collision is detected
                if (newElement != null) {
                    while (!existingElements.add(newElement))
                        ((SourceRefElement) newElement).occurrenceCount++;
                }
            }
            break;
        }
        if (newElement != null) {
            knownScopes.put(scope, newElement);
        }
        break;
    case Scope.METHOD_SCOPE:
        if (scope.isLambdaScope()) {
            parentElement = createElement(scope.parent, elementPosition, unit, existingElements, knownScopes);
            LambdaExpression expression = (LambdaExpression) scope.originalReferenceContext();
            if (expression.resolvedType != null && expression.resolvedType.isValidBinding()
                    && !(expression.descriptor instanceof ProblemMethodBinding)) { // chain in lambda element only if resolved properly.
                //newElement = new org.eclipse.jdt.internal.core.SourceLambdaExpression((JavaElement) parentElement, expression)
                // .getMethod();

                newElement = LambdaFactory.createLambdaExpression((JavaElement) parentElement, expression)
                        .getMethod();
                knownScopes.put(scope, newElement);
                return newElement;
            }
            return parentElement;
        }
        IType parentType = (IType) createElement(scope.parent, elementPosition, unit, existingElements,
                knownScopes);
        MethodScope methodScope = (MethodScope) scope;
        if (methodScope.isInsideInitializer()) {
            // inside field or initializer, must find proper one
            TypeDeclaration type = methodScope.referenceType();
            int occurenceCount = 1;
            int length = type.fields == null ? 0 : type.fields.length;
            for (int i = 0; i < length; i++) {
                FieldDeclaration field = type.fields[i];
                if (field.declarationSourceStart <= elementPosition
                        && elementPosition <= field.declarationSourceEnd) {
                    switch (field.getKind()) {
                    case AbstractVariableDeclaration.FIELD:
                    case AbstractVariableDeclaration.ENUM_CONSTANT:
                        newElement = parentType.getField(new String(field.name));
                        break;
                    case AbstractVariableDeclaration.INITIALIZER:
                        newElement = parentType.getInitializer(occurenceCount);
                        break;
                    }
                    break;
                } else if (field.getKind() == AbstractVariableDeclaration.INITIALIZER) {
                    occurenceCount++;
                }
            }
        } else {
            // method element
            AbstractMethodDeclaration method = methodScope.referenceMethod();
            newElement = parentType.getMethod(new String(method.selector),
                    Util.typeParameterSignatures(method));
            if (newElement != null) {
                knownScopes.put(scope, newElement);
            }
        }
        break;
    case Scope.BLOCK_SCOPE:
        // standard block, no element per se
        newElement = createElement(scope.parent, elementPosition, unit, existingElements, knownScopes);
        break;
    }
    return newElement;
}

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

License:Open Source License

protected void buildBodyDeclarations(org.eclipse.jdt.internal.compiler.ast.TypeDeclaration typeDeclaration,
        AbstractTypeDeclaration typeDecl, boolean isInterface) {
    // add body declaration in the lexical order
    org.eclipse.jdt.internal.compiler.ast.TypeDeclaration[] members = typeDeclaration.memberTypes;
    org.eclipse.jdt.internal.compiler.ast.FieldDeclaration[] fields = typeDeclaration.fields;
    org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration[] methods = typeDeclaration.methods;

    int fieldsLength = fields == null ? 0 : fields.length;
    int methodsLength = methods == null ? 0 : methods.length;
    int membersLength = members == null ? 0 : members.length;
    int fieldsIndex = 0;
    int methodsIndex = 0;
    int membersIndex = 0;

    while ((fieldsIndex < fieldsLength) || (membersIndex < membersLength) || (methodsIndex < methodsLength)) {
        org.eclipse.jdt.internal.compiler.ast.FieldDeclaration nextFieldDeclaration = null;
        org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration nextMethodDeclaration = null;
        org.eclipse.jdt.internal.compiler.ast.TypeDeclaration nextMemberDeclaration = null;

        int position = Integer.MAX_VALUE;
        int nextDeclarationType = -1;
        if (fieldsIndex < fieldsLength) {
            nextFieldDeclaration = fields[fieldsIndex];
            if (nextFieldDeclaration.declarationSourceStart < position) {
                position = nextFieldDeclaration.declarationSourceStart;
                nextDeclarationType = 0; // FIELD
            }//w  ww.ja  v  a2s .  c o m
        }
        if (methodsIndex < methodsLength) {
            nextMethodDeclaration = methods[methodsIndex];
            if (nextMethodDeclaration.declarationSourceStart < position) {
                position = nextMethodDeclaration.declarationSourceStart;
                nextDeclarationType = 1; // METHOD
            }
        }
        if (membersIndex < membersLength) {
            nextMemberDeclaration = members[membersIndex];
            if (nextMemberDeclaration.declarationSourceStart < position) {
                position = nextMemberDeclaration.declarationSourceStart;
                nextDeclarationType = 2; // MEMBER
            }
        }
        switch (nextDeclarationType) {
        case 0:
            if (nextFieldDeclaration.getKind() == AbstractVariableDeclaration.ENUM_CONSTANT) {
                typeDecl.bodyDeclarations().add(convert(nextFieldDeclaration));
            } else {
                checkAndAddMultipleFieldDeclaration(fields, fieldsIndex, typeDecl.bodyDeclarations());
            }
            fieldsIndex++;
            break;
        case 1:
            methodsIndex++;
            if (!nextMethodDeclaration.isDefaultConstructor() && !nextMethodDeclaration.isClinit()) {
                // GROOVY start - a little ugly, but allows the conversion of the method declaration
                // to know if it is occurring within a pure java type or not
                boolean originalValue = this.scannerUsable;
                try {
                    this.scannerUsable = typeDeclaration.isScannerUsableOnThisDeclaration();
                    // GROOVY end
                    typeDecl.bodyDeclarations().add(convert(isInterface, nextMethodDeclaration));
                    // GROOVY start
                } finally {
                    this.scannerUsable = originalValue;
                }
                // GROOVY end
            }
            break;
        case 2:
            membersIndex++;
            ASTNode node = convert(nextMemberDeclaration);
            if (node == null) {
                typeDecl.setFlags(typeDecl.getFlags() | ASTNode.MALFORMED);
            } else {
                typeDecl.bodyDeclarations().add(node);
            }
        }
    }
    // Convert javadoc
    convert(typeDeclaration.javadoc, typeDecl);
}

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

License:Open Source License

protected void buildBodyDeclarations(org.eclipse.jdt.internal.compiler.ast.TypeDeclaration enumDeclaration2,
        EnumDeclaration enumDeclaration) {
    // add body declaration in the lexical order
    org.eclipse.jdt.internal.compiler.ast.TypeDeclaration[] members = enumDeclaration2.memberTypes;
    org.eclipse.jdt.internal.compiler.ast.FieldDeclaration[] fields = enumDeclaration2.fields;
    org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration[] methods = enumDeclaration2.methods;

    int fieldsLength = fields == null ? 0 : fields.length;
    int methodsLength = methods == null ? 0 : methods.length;
    int membersLength = members == null ? 0 : members.length;
    int fieldsIndex = 0;
    int methodsIndex = 0;
    int membersIndex = 0;

    while ((fieldsIndex < fieldsLength) || (membersIndex < membersLength) || (methodsIndex < methodsLength)) {
        org.eclipse.jdt.internal.compiler.ast.FieldDeclaration nextFieldDeclaration = null;
        org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration nextMethodDeclaration = null;
        org.eclipse.jdt.internal.compiler.ast.TypeDeclaration nextMemberDeclaration = null;

        int position = Integer.MAX_VALUE;
        int nextDeclarationType = -1;
        if (fieldsIndex < fieldsLength) {
            nextFieldDeclaration = fields[fieldsIndex];
            if (nextFieldDeclaration.declarationSourceStart < position) {
                position = nextFieldDeclaration.declarationSourceStart;
                nextDeclarationType = 0; // FIELD
            }//from   w ww .jav  a 2 s  .  c  o m
        }
        if (methodsIndex < methodsLength) {
            nextMethodDeclaration = methods[methodsIndex];
            if (nextMethodDeclaration.declarationSourceStart < position) {
                position = nextMethodDeclaration.declarationSourceStart;
                nextDeclarationType = 1; // METHOD
            }
        }
        if (membersIndex < membersLength) {
            nextMemberDeclaration = members[membersIndex];
            if (nextMemberDeclaration.declarationSourceStart < position) {
                position = nextMemberDeclaration.declarationSourceStart;
                nextDeclarationType = 2; // MEMBER
            }
        }
        switch (nextDeclarationType) {
        case 0:
            if (nextFieldDeclaration.getKind() == AbstractVariableDeclaration.ENUM_CONSTANT) {
                enumDeclaration.enumConstants().add(convert(nextFieldDeclaration));
            } else {
                checkAndAddMultipleFieldDeclaration(fields, fieldsIndex, enumDeclaration.bodyDeclarations());
            }
            fieldsIndex++;
            break;
        case 1:
            methodsIndex++;
            if (!nextMethodDeclaration.isDefaultConstructor() && !nextMethodDeclaration.isClinit()) {
                enumDeclaration.bodyDeclarations().add(convert(false, nextMethodDeclaration));
            }
            break;
        case 2:
            membersIndex++;
            enumDeclaration.bodyDeclarations().add(convert(nextMemberDeclaration));
            break;
        }
    }
    convert(enumDeclaration2.javadoc, enumDeclaration);
}

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

License:Open Source License

protected void buildBodyDeclarations(org.eclipse.jdt.internal.compiler.ast.TypeDeclaration expression,
        AnonymousClassDeclaration anonymousClassDeclaration) {
    // add body declaration in the lexical order
    org.eclipse.jdt.internal.compiler.ast.TypeDeclaration[] members = expression.memberTypes;
    org.eclipse.jdt.internal.compiler.ast.FieldDeclaration[] fields = expression.fields;
    org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration[] methods = expression.methods;

    int fieldsLength = fields == null ? 0 : fields.length;
    int methodsLength = methods == null ? 0 : methods.length;
    int membersLength = members == null ? 0 : members.length;
    int fieldsIndex = 0;
    int methodsIndex = 0;
    int membersIndex = 0;

    while ((fieldsIndex < fieldsLength) || (membersIndex < membersLength) || (methodsIndex < methodsLength)) {
        org.eclipse.jdt.internal.compiler.ast.FieldDeclaration nextFieldDeclaration = null;
        org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration nextMethodDeclaration = null;
        org.eclipse.jdt.internal.compiler.ast.TypeDeclaration nextMemberDeclaration = null;

        int position = Integer.MAX_VALUE;
        int nextDeclarationType = -1;
        if (fieldsIndex < fieldsLength) {
            nextFieldDeclaration = fields[fieldsIndex];
            if (nextFieldDeclaration.declarationSourceStart < position) {
                position = nextFieldDeclaration.declarationSourceStart;
                nextDeclarationType = 0; // FIELD
            }//from  www  .  java2 s  .c o  m
        }
        if (methodsIndex < methodsLength) {
            nextMethodDeclaration = methods[methodsIndex];
            if (nextMethodDeclaration.declarationSourceStart < position) {
                position = nextMethodDeclaration.declarationSourceStart;
                nextDeclarationType = 1; // METHOD
            }
        }
        if (membersIndex < membersLength) {
            nextMemberDeclaration = members[membersIndex];
            if (nextMemberDeclaration.declarationSourceStart < position) {
                position = nextMemberDeclaration.declarationSourceStart;
                nextDeclarationType = 2; // MEMBER
            }
        }
        switch (nextDeclarationType) {
        case 0:
            if (nextFieldDeclaration.getKind() == AbstractVariableDeclaration.ENUM_CONSTANT) {
                anonymousClassDeclaration.bodyDeclarations().add(convert(nextFieldDeclaration));
            } else {
                checkAndAddMultipleFieldDeclaration(fields, fieldsIndex,
                        anonymousClassDeclaration.bodyDeclarations());
            }
            fieldsIndex++;
            break;
        case 1:
            methodsIndex++;
            if (!nextMethodDeclaration.isDefaultConstructor() && !nextMethodDeclaration.isClinit()) {
                anonymousClassDeclaration.bodyDeclarations().add(convert(false, nextMethodDeclaration));
            }
            break;
        case 2:
            membersIndex++;
            ASTNode node = convert(nextMemberDeclaration);
            if (node == null) {
                anonymousClassDeclaration.setFlags(anonymousClassDeclaration.getFlags() | ASTNode.MALFORMED);
            } else {
                anonymousClassDeclaration.bodyDeclarations().add(node);
            }
        }
    }
}

From source file:org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding.java

License:Open Source License

public FieldBinding resolveTypeFor(FieldBinding field) {
    if ((field.modifiers & ExtraCompilerModifiers.AccUnresolved) == 0)
        return field;

    if (this.scope.compilerOptions().sourceLevel >= ClassFileConstants.JDK1_5) {
        if ((field.getAnnotationTagBits() & TagBits.AnnotationDeprecated) != 0)
            field.modifiers |= ClassFileConstants.AccDeprecated;
    }/*from w  w w  .ja v  a 2  s  .  com*/
    if (isViewedAsDeprecated() && !field.isDeprecated())
        field.modifiers |= ExtraCompilerModifiers.AccDeprecatedImplicitly;
    if (hasRestrictedAccess())
        field.modifiers |= ExtraCompilerModifiers.AccRestrictedAccess;
    FieldDeclaration[] fieldDecls = this.scope.referenceContext.fields;
    int length = fieldDecls == null ? 0 : fieldDecls.length;
    for (int f = 0; f < length; f++) {
        if (fieldDecls[f].binding != field)
            continue;

        MethodScope initializationScope = field.isStatic() ? this.scope.referenceContext.staticInitializerScope
                : this.scope.referenceContext.initializerScope;
        FieldBinding previousField = initializationScope.initializedField;
        try {
            initializationScope.initializedField = field;
            FieldDeclaration fieldDecl = fieldDecls[f];
            TypeBinding fieldType = fieldDecl.getKind() == AbstractVariableDeclaration.ENUM_CONSTANT
                    ? initializationScope.environment().convertToRawType(this,
                            false /*do not force conversion of enclosing types*/) // enum constant is implicitly of declaring enum type
                    : fieldDecl.type.resolveType(initializationScope, true /* check bounds*/);
            field.type = fieldType;
            field.modifiers &= ~ExtraCompilerModifiers.AccUnresolved;
            if (fieldType == null) {
                fieldDecl.binding = null;
                return null;
            }
            if (fieldType == TypeBinding.VOID) {
                this.scope.problemReporter().variableTypeCannotBeVoid(fieldDecl);
                fieldDecl.binding = null;
                return null;
            }
            if (fieldType.isArrayType() && ((ArrayBinding) fieldType).leafComponentType == TypeBinding.VOID) {
                this.scope.problemReporter().variableTypeCannotBeVoidArray(fieldDecl);
                fieldDecl.binding = null;
                return null;
            }
            if ((fieldType.tagBits & TagBits.HasMissingType) != 0) {
                field.tagBits |= TagBits.HasMissingType;
            }
            TypeBinding leafType = fieldType.leafComponentType();
            if (leafType instanceof ReferenceBinding && (((ReferenceBinding) leafType).modifiers
                    & ExtraCompilerModifiers.AccGenericSignature) != 0) {
                field.modifiers |= ExtraCompilerModifiers.AccGenericSignature;
            }
        } finally {
            initializationScope.initializedField = previousField;
        }
        return field;
    }
    return null; // should never reach this point
}

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

License:Open Source License

protected void dispatchDeclarationIntoEnumDeclaration(int length) {

    if (length == 0)
        return;/*from   w w w .j  a  v  a  2s . com*/
    int[] flag = new int[length + 1]; //plus one -- see <HERE>
    int size1 = 0, size2 = 0, size3 = 0;
    TypeDeclaration enumDeclaration = (TypeDeclaration) this.astStack[this.astPtr - length];
    boolean hasAbstractMethods = false;
    int enumConstantsCounter = 0;
    for (int i = length - 1; i >= 0; i--) {
        ASTNode astNode = this.astStack[this.astPtr--];
        if (astNode instanceof AbstractMethodDeclaration) {
            //methods and constructors have been regrouped into one single list
            flag[i] = 2;
            size2++;
            if (((AbstractMethodDeclaration) astNode).isAbstract()) {
                hasAbstractMethods = true;
            }
        } else if (astNode instanceof TypeDeclaration) {
            flag[i] = 3;
            size3++;
        } else if (astNode instanceof FieldDeclaration) {
            flag[i] = 1;
            size1++;
            if (((FieldDeclaration) astNode).getKind() == AbstractVariableDeclaration.ENUM_CONSTANT) {
                enumConstantsCounter++;
            }
        }
    }

    //arrays creation
    if (size1 != 0) {
        enumDeclaration.fields = new FieldDeclaration[size1];
    }
    if (size2 != 0) {
        enumDeclaration.methods = new AbstractMethodDeclaration[size2];
        if (hasAbstractMethods)
            enumDeclaration.bits |= ASTNode.HasAbstractMethods;
    }
    if (size3 != 0) {
        enumDeclaration.memberTypes = new TypeDeclaration[size3];
    }

    //arrays fill up
    size1 = size2 = size3 = 0;
    int flagI = flag[0], start = 0;
    int length2;
    for (int end = 0; end <= length; end++) //<HERE> the plus one allows to
    {
        if (flagI != flag[end]) //treat the last element as a ended flag.....
        { //array copy
            switch (flagI) {
            case 1:
                size1 += (length2 = end - start);
                System.arraycopy(this.astStack, this.astPtr + start + 1, enumDeclaration.fields,
                        size1 - length2, length2);
                break;
            case 2:
                size2 += (length2 = end - start);
                System.arraycopy(this.astStack, this.astPtr + start + 1, enumDeclaration.methods,
                        size2 - length2, length2);
                break;
            case 3:
                size3 += (length2 = end - start);
                System.arraycopy(this.astStack, this.astPtr + start + 1, enumDeclaration.memberTypes,
                        size3 - length2, length2);
                break;
            }
            flagI = flag[start = end];
        }
    }

    if (enumDeclaration.memberTypes != null) {
        for (int i = enumDeclaration.memberTypes.length - 1; i >= 0; i--) {
            enumDeclaration.memberTypes[i].enclosingType = enumDeclaration;
        }
    }
    enumDeclaration.enumConstantsCounter = enumConstantsCounter;
}