Example usage for org.eclipse.jdt.internal.compiler.lookup TagBits ContainsNestedTypeReferences

List of usage examples for org.eclipse.jdt.internal.compiler.lookup TagBits ContainsNestedTypeReferences

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.compiler.lookup TagBits ContainsNestedTypeReferences.

Prototype

long ContainsNestedTypeReferences

To view the source code for org.eclipse.jdt.internal.compiler.lookup TagBits ContainsNestedTypeReferences.

Click Source Link

Usage

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

License:Open Source License

/**
 * Connect type variable supertypes, and returns true if no problem was detected
 * @param typeParameters// w ww.  j a v a2  s.  c  o  m
 * @param checkForErasedCandidateCollisions
 */
protected boolean connectTypeVariables(TypeParameter[] typeParameters,
        boolean checkForErasedCandidateCollisions) {
    /* https://bugs.eclipse.org/bugs/show_bug.cgi?id=305259 - We used to not bother with connecting
       type variables if source level is < 1.5. This creates problems in the reconciler if a 1.4
       project references the generified API of a 1.5 project. The "current" project's source
       level cannot decide this question for some other project. Now, if we see type parameters
       at all, we assume that the concerned java element has some legitimate business with them.
     */
    if (typeParameters == null || typeParameters.length == 0)
        return true;
    Map invocations = new HashMap(2);
    boolean noProblems = true;
    // preinitializing each type variable
    for (int i = 0, paramLength = typeParameters.length; i < paramLength; i++) {
        TypeParameter typeParameter = typeParameters[i];
        TypeVariableBinding typeVariable = typeParameter.binding;
        if (typeVariable == null)
            return false;

        typeVariable.superclass = getJavaLangObject();
        typeVariable.superInterfaces = Binding.NO_SUPERINTERFACES;
        // set firstBound to the binding of the first explicit bound in parameter declaration
        typeVariable.firstBound = null; // first bound used to compute erasure
    }
    nextVariable: for (int i = 0, paramLength = typeParameters.length; i < paramLength; i++) {
        TypeParameter typeParameter = typeParameters[i];
        TypeVariableBinding typeVariable = typeParameter.binding;
        TypeReference typeRef = typeParameter.type;
        if (typeRef == null)
            continue nextVariable;
        boolean isFirstBoundTypeVariable = false;
        TypeBinding superType = this.kind == METHOD_SCOPE
                ? typeRef.resolveType((BlockScope) this, false/*no bound check*/)
                : typeRef.resolveType((ClassScope) this);
        if (superType == null) {
            typeVariable.tagBits |= TagBits.HierarchyHasProblems;
        } else {
            typeRef.resolvedType = superType; // hold onto the problem type
            firstBound: {
                switch (superType.kind()) {
                case Binding.ARRAY_TYPE:
                    problemReporter().boundCannotBeArray(typeRef, superType);
                    typeVariable.tagBits |= TagBits.HierarchyHasProblems;
                    break firstBound; // do not keep first bound
                case Binding.TYPE_PARAMETER:
                    isFirstBoundTypeVariable = true;
                    TypeVariableBinding varSuperType = (TypeVariableBinding) superType;
                    if (varSuperType.rank >= typeVariable.rank
                            && varSuperType.declaringElement == typeVariable.declaringElement) {
                        if (compilerOptions().complianceLevel <= ClassFileConstants.JDK1_6) {
                            problemReporter().forwardTypeVariableReference(typeParameter, varSuperType);
                            typeVariable.tagBits |= TagBits.HierarchyHasProblems;
                            break firstBound; // do not keep first bound
                        }
                    }
                    // https://bugs.eclipse.org/bugs/show_bug.cgi?id=335751
                    if (compilerOptions().complianceLevel > ClassFileConstants.JDK1_6) {
                        if (typeVariable.rank >= varSuperType.rank
                                && varSuperType.declaringElement == typeVariable.declaringElement) {
                            SimpleSet set = new SimpleSet(typeParameters.length);
                            set.add(typeVariable);
                            ReferenceBinding superBinding = varSuperType;
                            while (superBinding instanceof TypeVariableBinding) {
                                if (set.includes(superBinding)) {
                                    problemReporter().hierarchyCircularity(typeVariable, varSuperType, typeRef);
                                    typeVariable.tagBits |= TagBits.HierarchyHasProblems;
                                    break firstBound; // do not keep first bound
                                } else {
                                    set.add(superBinding);
                                    superBinding = ((TypeVariableBinding) superBinding).superclass;
                                }
                            }
                        }
                    }
                    break;
                default:
                    if (((ReferenceBinding) superType).isFinal()) {
                        problemReporter().finalVariableBound(typeVariable, typeRef);
                    }
                    break;
                }
                ReferenceBinding superRefType = (ReferenceBinding) superType;
                if (!superType.isInterface()) {
                    typeVariable.superclass = superRefType;
                } else {
                    typeVariable.superInterfaces = new ReferenceBinding[] { superRefType };
                }
                typeVariable.tagBits |= superType.tagBits & TagBits.ContainsNestedTypeReferences;
                typeVariable.firstBound = superRefType; // first bound used to compute erasure
            }
        }
        TypeReference[] boundRefs = typeParameter.bounds;
        if (boundRefs != null) {
            nextBound: for (int j = 0, boundLength = boundRefs.length; j < boundLength; j++) {
                typeRef = boundRefs[j];
                superType = this.kind == METHOD_SCOPE ? typeRef.resolveType((BlockScope) this, false)
                        : typeRef.resolveType((ClassScope) this);
                if (superType == null) {
                    typeVariable.tagBits |= TagBits.HierarchyHasProblems;
                    continue nextBound;
                } else {
                    typeVariable.tagBits |= superType.tagBits & TagBits.ContainsNestedTypeReferences;
                    boolean didAlreadyComplain = !typeRef.resolvedType.isValidBinding();
                    if (isFirstBoundTypeVariable && j == 0) {
                        problemReporter().noAdditionalBoundAfterTypeVariable(typeRef);
                        typeVariable.tagBits |= TagBits.HierarchyHasProblems;
                        didAlreadyComplain = true;
                        //continue nextBound; - keep these bounds to minimize secondary errors
                    } else if (superType.isArrayType()) {
                        if (!didAlreadyComplain) {
                            problemReporter().boundCannotBeArray(typeRef, superType);
                            typeVariable.tagBits |= TagBits.HierarchyHasProblems;
                        }
                        continue nextBound;
                    } else {
                        if (!superType.isInterface()) {
                            if (!didAlreadyComplain) {
                                problemReporter().boundMustBeAnInterface(typeRef, superType);
                                typeVariable.tagBits |= TagBits.HierarchyHasProblems;
                            }
                            continue nextBound;
                        }
                    }
                    // check against superclass
                    if (checkForErasedCandidateCollisions
                            && typeVariable.firstBound == typeVariable.superclass) {
                        if (hasErasedCandidatesCollisions(superType, typeVariable.superclass, invocations,
                                typeVariable, typeRef)) {
                            continue nextBound;
                        }
                    }
                    // check against superinterfaces
                    ReferenceBinding superRefType = (ReferenceBinding) superType;
                    for (int index = typeVariable.superInterfaces.length; --index >= 0;) {
                        ReferenceBinding previousInterface = typeVariable.superInterfaces[index];
                        if (previousInterface == superRefType) {
                            problemReporter().duplicateBounds(typeRef, superType);
                            typeVariable.tagBits |= TagBits.HierarchyHasProblems;
                            continue nextBound;
                        }
                        if (checkForErasedCandidateCollisions) {
                            if (hasErasedCandidatesCollisions(superType, previousInterface, invocations,
                                    typeVariable, typeRef)) {
                                continue nextBound;
                            }
                        }
                    }
                    int size = typeVariable.superInterfaces.length;
                    System.arraycopy(typeVariable.superInterfaces, 0,
                            typeVariable.superInterfaces = new ReferenceBinding[size + 1], 0, size);
                    typeVariable.superInterfaces[size] = superRefType;
                }
            }
        }
        noProblems &= (typeVariable.tagBits & TagBits.HierarchyHasProblems) == 0;
    }
    return noProblems;
}