Example usage for org.eclipse.jdt.internal.compiler.lookup Binding RAW_TYPE

List of usage examples for org.eclipse.jdt.internal.compiler.lookup Binding RAW_TYPE

Introduction

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

Prototype

int RAW_TYPE

To view the source code for org.eclipse.jdt.internal.compiler.lookup Binding RAW_TYPE.

Click Source Link

Usage

From source file:lombok.eclipse.agent.PatchVal.java

License:Open Source License

private static TypeBinding getForEachComponentType(Expression collection, BlockScope scope) {
    if (collection != null) {
        TypeBinding resolved = collection.resolvedType;
        if (resolved == null)
            resolved = collection.resolveType(scope);
        if (resolved == null)
            return null;
        if (resolved.isArrayType()) {
            resolved = ((ArrayBinding) resolved).elementsType();
            return resolved;
        } else if (resolved instanceof ReferenceBinding) {
            ReferenceBinding iterableType = ((ReferenceBinding) resolved)
                    .findSuperTypeOriginatingFrom(TypeIds.T_JavaLangIterable, false);

            TypeBinding[] arguments = null;
            if (iterableType != null)
                switch (iterableType.kind()) {
                case Binding.GENERIC_TYPE: // for (T t : Iterable<T>) - in case used inside Iterable itself
                    arguments = iterableType.typeVariables();
                    break;
                case Binding.PARAMETERIZED_TYPE: // for(E e : Iterable<E>)
                    arguments = ((ParameterizedTypeBinding) iterableType).arguments;
                    break;
                case Binding.RAW_TYPE: // for(Object e : Iterable)
                    return null;
                }/* w ww . j  a v a  2 s.c o  m*/

            if (arguments != null && arguments.length == 1) {
                return arguments[0];
            }
        }
    }

    return null;
}

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

License:Open Source License

boolean areTypesEqual(TypeBinding one, TypeBinding two) {
    if (one == two)
        return true;
    // https://bugs.eclipse.org/bugs/show_bug.cgi?id=329584
    switch (one.kind()) {
    case Binding.TYPE:
        switch (two.kind()) {
        case Binding.PARAMETERIZED_TYPE:
        case Binding.RAW_TYPE:
            if (one == two.erasure())
                return true;
        }// w  ww.ja v a 2 s  .c o m
        break;
    case Binding.RAW_TYPE:
    case Binding.PARAMETERIZED_TYPE:
        switch (two.kind()) {
        case Binding.TYPE:
            if (one.erasure() == two)
                return true;
        }
    }

    // need to consider X<?> and X<? extends Object> as the same 'type'
    if (one.isParameterizedType() && two.isParameterizedType())
        return one.isEquivalentTo(two) && two.isEquivalentTo(one);

    // Can skip this since we resolved each method before comparing it, see computeSubstituteMethod()
    //   if (one instanceof UnresolvedReferenceBinding)
    //      return ((UnresolvedReferenceBinding) one).resolvedType == two;
    //   if (two instanceof UnresolvedReferenceBinding)
    //      return ((UnresolvedReferenceBinding) two).resolvedType == one;
    return false; // all other type bindings are identical
}

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

License:Open Source License

/**
 * Answer true if the receiver type can be assigned to the argument type (right)
 *//*from w ww.j  ava2s.com*/
private boolean isCompatibleWith0(TypeBinding otherType) {
    if (otherType == this)
        return true;
    if (otherType.id == TypeIds.T_JavaLangObject)
        return true;
    // equivalence may allow compatibility with array type through wildcard
    // bound
    if (isEquivalentTo(otherType))
        return true;
    switch (otherType.kind()) {
    case Binding.WILDCARD_TYPE:
    case Binding.INTERSECTION_TYPE:
        return false; // should have passed equivalence check above if
                      // wildcard
    case Binding.TYPE_PARAMETER:
        // check compatibility with capture of ? super X
        if (otherType.isCapture()) {
            CaptureBinding otherCapture = (CaptureBinding) otherType;
            TypeBinding otherLowerBound;
            if ((otherLowerBound = otherCapture.lowerBound) != null) {
                if (otherLowerBound.isArrayType())
                    return false;
                return isCompatibleWith(otherLowerBound);
            }
        }
        //$FALL-THROUGH$
    case Binding.GENERIC_TYPE:
    case Binding.TYPE:
    case Binding.PARAMETERIZED_TYPE:
    case Binding.RAW_TYPE:
        switch (kind()) {
        case Binding.GENERIC_TYPE:
        case Binding.PARAMETERIZED_TYPE:
        case Binding.RAW_TYPE:
            if (erasure() == otherType.erasure())
                return false; // should have passed equivalence check
                              // above if same erasure
        }
        ReferenceBinding otherReferenceType = (ReferenceBinding) otherType;
        if (otherReferenceType.isInterface()) // could be annotation type
            return implementsInterface(otherReferenceType, true);
        if (isInterface()) // Explicit conversion from an interface
                           // to a class is not allowed
            return false;
        return otherReferenceType.isSuperclassOf(this);
    default:
        return false;
    }
}

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

License:Open Source License

/**
 * Returns a type where either all variables or specific ones got discarded.
 * e.g. List<E> (discarding <E extends Enum<E>) will return:  List<? extends Enum<?>>
 *//*from   www  .j  av a2s.  c om*/
public static TypeBinding convertEliminatingTypeVariables(TypeBinding originalType,
        ReferenceBinding genericType, int rank, Set eliminatedVariables) {
    if ((originalType.tagBits & TagBits.HasTypeVariable) != 0) {
        switch (originalType.kind()) {
        case Binding.ARRAY_TYPE:
            ArrayBinding originalArrayType = (ArrayBinding) originalType;
            TypeBinding originalLeafComponentType = originalArrayType.leafComponentType;
            TypeBinding substitute = convertEliminatingTypeVariables(originalLeafComponentType, genericType,
                    rank, eliminatedVariables); // substitute could itself be array type
            if (substitute != originalLeafComponentType) {
                return originalArrayType.environment.createArrayType(substitute.leafComponentType(),
                        substitute.dimensions() + originalArrayType.dimensions());
            }
            break;
        case Binding.PARAMETERIZED_TYPE:
            ParameterizedTypeBinding paramType = (ParameterizedTypeBinding) originalType;
            ReferenceBinding originalEnclosing = paramType.enclosingType();
            ReferenceBinding substitutedEnclosing = originalEnclosing;
            if (originalEnclosing != null) {
                substitutedEnclosing = (ReferenceBinding) convertEliminatingTypeVariables(originalEnclosing,
                        genericType, rank, eliminatedVariables);
            }
            TypeBinding[] originalArguments = paramType.arguments;
            TypeBinding[] substitutedArguments = originalArguments;
            for (int i = 0, length = originalArguments == null ? 0
                    : originalArguments.length; i < length; i++) {
                TypeBinding originalArgument = originalArguments[i];
                TypeBinding substitutedArgument = convertEliminatingTypeVariables(originalArgument,
                        paramType.genericType(), i, eliminatedVariables);
                if (substitutedArgument != originalArgument) {
                    if (substitutedArguments == originalArguments) {
                        System.arraycopy(originalArguments, 0, substitutedArguments = new TypeBinding[length],
                                0, i);
                    }
                    substitutedArguments[i] = substitutedArgument;
                } else if (substitutedArguments != originalArguments) {
                    substitutedArguments[i] = originalArgument;
                }
            }
            if (originalEnclosing != substitutedEnclosing || originalArguments != substitutedArguments) {
                return paramType.environment.createParameterizedType(paramType.genericType(),
                        substitutedArguments, substitutedEnclosing);
            }
            break;
        case Binding.TYPE_PARAMETER:
            if (genericType == null) {
                break;
            }
            TypeVariableBinding originalVariable = (TypeVariableBinding) originalType;
            if (eliminatedVariables != null && eliminatedVariables.contains(originalType)) {
                return originalVariable.environment.createWildcard(genericType, rank, null, null,
                        Wildcard.UNBOUND);
            }
            TypeBinding originalUpperBound = originalVariable.upperBound();
            if (eliminatedVariables == null) {
                eliminatedVariables = new HashSet(2);
            }
            eliminatedVariables.add(originalVariable);
            TypeBinding substitutedUpperBound = convertEliminatingTypeVariables(originalUpperBound, genericType,
                    rank, eliminatedVariables);
            eliminatedVariables.remove(originalVariable);
            return originalVariable.environment.createWildcard(genericType, rank, substitutedUpperBound, null,
                    Wildcard.EXTENDS);
        case Binding.RAW_TYPE:
            break;
        case Binding.GENERIC_TYPE:
            ReferenceBinding currentType = (ReferenceBinding) originalType;
            originalEnclosing = currentType.enclosingType();
            substitutedEnclosing = originalEnclosing;
            if (originalEnclosing != null) {
                substitutedEnclosing = (ReferenceBinding) convertEliminatingTypeVariables(originalEnclosing,
                        genericType, rank, eliminatedVariables);
            }
            originalArguments = currentType.typeVariables();
            substitutedArguments = originalArguments;
            for (int i = 0, length = originalArguments == null ? 0
                    : originalArguments.length; i < length; i++) {
                TypeBinding originalArgument = originalArguments[i];
                TypeBinding substitutedArgument = convertEliminatingTypeVariables(originalArgument, currentType,
                        i, eliminatedVariables);
                if (substitutedArgument != originalArgument) {
                    if (substitutedArguments == originalArguments) {
                        System.arraycopy(originalArguments, 0, substitutedArguments = new TypeBinding[length],
                                0, i);
                    }
                    substitutedArguments[i] = substitutedArgument;
                } else if (substitutedArguments != originalArguments) {
                    substitutedArguments[i] = originalArgument;
                }
            }
            if (originalEnclosing != substitutedEnclosing || originalArguments != substitutedArguments) {
                return ((TypeVariableBinding) originalArguments[0]).environment
                        .createParameterizedType(genericType, substitutedArguments, substitutedEnclosing);
            }
            break;
        case Binding.WILDCARD_TYPE:
            WildcardBinding wildcard = (WildcardBinding) originalType;
            TypeBinding originalBound = wildcard.bound;
            TypeBinding substitutedBound = originalBound;
            if (originalBound != null) {
                substitutedBound = convertEliminatingTypeVariables(originalBound, genericType, rank,
                        eliminatedVariables);
                if (substitutedBound != originalBound) {
                    return wildcard.environment.createWildcard(wildcard.genericType, wildcard.rank,
                            substitutedBound, null, wildcard.boundKind);
                }
            }
            break;
        case Binding.INTERSECTION_TYPE:
            WildcardBinding intersection = (WildcardBinding) originalType;
            originalBound = intersection.bound;
            substitutedBound = originalBound;
            if (originalBound != null) {
                substitutedBound = convertEliminatingTypeVariables(originalBound, genericType, rank,
                        eliminatedVariables);
            }
            TypeBinding[] originalOtherBounds = intersection.otherBounds;
            TypeBinding[] substitutedOtherBounds = originalOtherBounds;
            for (int i = 0, length = originalOtherBounds == null ? 0
                    : originalOtherBounds.length; i < length; i++) {
                TypeBinding originalOtherBound = originalOtherBounds[i];
                TypeBinding substitutedOtherBound = convertEliminatingTypeVariables(originalOtherBound,
                        genericType, rank, eliminatedVariables);
                if (substitutedOtherBound != originalOtherBound) {
                    if (substitutedOtherBounds == originalOtherBounds) {
                        System.arraycopy(originalOtherBounds, 0,
                                substitutedOtherBounds = new TypeBinding[length], 0, i);
                    }
                    substitutedOtherBounds[i] = substitutedOtherBound;
                } else if (substitutedOtherBounds != originalOtherBounds) {
                    substitutedOtherBounds[i] = originalOtherBound;
                }
            }
            if (substitutedBound != originalBound || substitutedOtherBounds != originalOtherBounds) {
                return intersection.environment.createWildcard(intersection.genericType, intersection.rank,
                        substitutedBound, substitutedOtherBounds, intersection.boundKind);
            }
            break;
        }
    }
    return originalType;
}

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

License:Open Source License

protected boolean isAcceptableMethod(MethodBinding one, MethodBinding two) {
    TypeBinding[] oneParams = one.parameters;
    TypeBinding[] twoParams = two.parameters;
    int oneParamsLength = oneParams.length;
    int twoParamsLength = twoParams.length;
    if (oneParamsLength == twoParamsLength) {
        /* Below 1.5, discard any generics we have left in for the method verifier's benefit, (so it
           can detect method overriding properly in the presence of generic super types.) This is so
           as to allow us to determine whether we have been handed an acceptable method in 1.4 terms
           without all the 1.5isms below kicking in and spoiling the party.
           See https://bugs.eclipse.org/bugs/show_bug.cgi?id=331446
        *//*from   ww  w  .j a  v a2  s  .  com*/
        boolean applyErasure = environment().globalOptions.sourceLevel < ClassFileConstants.JDK1_5;
        next: for (int i = 0; i < oneParamsLength; i++) {
            TypeBinding oneParam = applyErasure ? oneParams[i].erasure() : oneParams[i];
            TypeBinding twoParam = applyErasure ? twoParams[i].erasure() : twoParams[i];
            if (oneParam == twoParam || oneParam.isCompatibleWith(twoParam)) {
                if (two.declaringClass.isRawType())
                    continue next;

                TypeBinding leafComponentType = two.original().parameters[i].leafComponentType();
                TypeBinding originalTwoParam = applyErasure ? leafComponentType.erasure() : leafComponentType;
                switch (originalTwoParam.kind()) {
                case Binding.TYPE_PARAMETER:
                    if (((TypeVariableBinding) originalTwoParam).hasOnlyRawBounds())
                        continue next;
                    //$FALL-THROUGH$
                case Binding.WILDCARD_TYPE:
                case Binding.INTERSECTION_TYPE:
                case Binding.PARAMETERIZED_TYPE:
                    TypeBinding originalOneParam = one.original().parameters[i].leafComponentType();
                    switch (originalOneParam.kind()) {
                    case Binding.TYPE:
                    case Binding.GENERIC_TYPE:
                        TypeBinding inheritedTwoParam = oneParam.findSuperTypeOriginatingFrom(twoParam);
                        if (inheritedTwoParam == null || !inheritedTwoParam.leafComponentType().isRawType())
                            break;
                        return false;
                    case Binding.TYPE_PARAMETER:
                        if (!((TypeVariableBinding) originalOneParam).upperBound().isRawType())
                            break;
                        return false;
                    case Binding.RAW_TYPE:
                        // originalOneParam is RAW so it cannot be more specific than a wildcard or parameterized type
                        return false;
                    }
                }
            } else {
                if (i == oneParamsLength - 1 && one.isVarargs() && two.isVarargs()) {
                    TypeBinding eType = ((ArrayBinding) twoParam).elementsType();
                    if (oneParam == eType || oneParam.isCompatibleWith(eType))
                        return true; // special case to choose between 2 varargs methods when the last arg is Object[]
                }
                return false;
            }
        }
        return true;
    }

    if (one.isVarargs() && two.isVarargs()) {
        if (oneParamsLength > twoParamsLength) {
            // special case when autoboxing makes (int, int...) better than (Object...) but not (int...) or (Integer, int...)
            if (((ArrayBinding) twoParams[twoParamsLength - 1]).elementsType().id != TypeIds.T_JavaLangObject)
                return false;
        }
        // check that each parameter before the vararg parameters are compatible (no autoboxing allowed here)
        for (int i = (oneParamsLength > twoParamsLength ? twoParamsLength : oneParamsLength) - 2; i >= 0; i--)
            if (oneParams[i] != twoParams[i] && !oneParams[i].isCompatibleWith(twoParams[i]))
                return false;
        if (parameterCompatibilityLevel(one, twoParams) == NOT_COMPATIBLE
                && parameterCompatibilityLevel(two, oneParams) == VARARGS_COMPATIBLE)
            return true;
    }
    return false;
}

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

License:Open Source License

private TypeBinding leastContainingInvocation(TypeBinding mec, Object invocationData, List lubStack) {
    if (invocationData == null)
        return mec; // no alternate invocation
    if (invocationData instanceof TypeBinding) { // only one invocation, simply return it (array only allocated if more than one)
        return (TypeBinding) invocationData;
    }/*  w w  w  .j  a va2  s .  c  om*/
    TypeBinding[] invocations = (TypeBinding[]) invocationData;

    // if mec is an array type, intersect invocation leaf component types, then promote back to array
    int dim = mec.dimensions();
    mec = mec.leafComponentType();

    int argLength = mec.typeVariables().length;
    if (argLength == 0)
        return mec; // should be caught by no invocation check

    // infer proper parameterized type from invocations
    TypeBinding[] bestArguments = new TypeBinding[argLength];
    for (int i = 0, length = invocations.length; i < length; i++) {
        TypeBinding invocation = invocations[i].leafComponentType();
        switch (invocation.kind()) {
        case Binding.GENERIC_TYPE:
            TypeVariableBinding[] invocationVariables = invocation.typeVariables();
            for (int j = 0; j < argLength; j++) {
                TypeBinding bestArgument = leastContainingTypeArgument(bestArguments[j], invocationVariables[j],
                        (ReferenceBinding) mec, j, lubStack);
                if (bestArgument == null)
                    return null;
                bestArguments[j] = bestArgument;
            }
            break;
        case Binding.PARAMETERIZED_TYPE:
            ParameterizedTypeBinding parameterizedType = (ParameterizedTypeBinding) invocation;
            for (int j = 0; j < argLength; j++) {
                TypeBinding bestArgument = leastContainingTypeArgument(bestArguments[j],
                        parameterizedType.arguments[j], (ReferenceBinding) mec, j, lubStack);
                if (bestArgument == null)
                    return null;
                bestArguments[j] = bestArgument;
            }
            break;
        case Binding.RAW_TYPE:
            return dim == 0 ? invocation : environment().createArrayType(invocation, dim); // raw type is taking precedence
        }
    }
    TypeBinding least = environment().createParameterizedType((ReferenceBinding) mec.erasure(), bestArguments,
            mec.enclosingType());
    return dim == 0 ? least : environment().createArrayType(least, dim);
}

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

License:Open Source License

/**
 * Returns the most specific set of types compatible with all given types.
 * (i.e. most specific common super types)
 * If no types is given, will return an empty array. If not compatible
 * reference type is found, returns null. In other cases, will return an array
 * of minimal erased types, where some nulls may appear (and must simply be
 * ignored).//from   w w w  .ja  v a2  s.co m
 */
protected TypeBinding[] minimalErasedCandidates(TypeBinding[] types, Map allInvocations) {
    int length = types.length;
    int indexOfFirst = -1, actualLength = 0;
    for (int i = 0; i < length; i++) {
        TypeBinding type = types[i];
        if (type == null)
            continue;
        if (type.isBaseType())
            return null;
        if (indexOfFirst < 0)
            indexOfFirst = i;
        actualLength++;
    }
    switch (actualLength) {
    case 0:
        return Binding.NO_TYPES;
    case 1:
        return types;
    }
    TypeBinding firstType = types[indexOfFirst];
    if (firstType.isBaseType())
        return null;

    // record all supertypes of type
    // intersect with all supertypes of otherType
    ArrayList typesToVisit = new ArrayList(5);

    int dim = firstType.dimensions();
    TypeBinding leafType = firstType.leafComponentType();
    // do not allow type variables/intersection types to match with erasures for free
    TypeBinding firstErasure;
    switch (leafType.kind()) {
    case Binding.PARAMETERIZED_TYPE:
    case Binding.RAW_TYPE:
    case Binding.ARRAY_TYPE:
        firstErasure = firstType.erasure();
        break;
    default:
        firstErasure = firstType;
        break;
    }
    if (firstErasure != firstType) {
        allInvocations.put(firstErasure, firstType);
    }
    typesToVisit.add(firstType);
    int max = 1;
    ReferenceBinding currentType;
    for (int i = 0; i < max; i++) {
        TypeBinding typeToVisit = (TypeBinding) typesToVisit.get(i);
        dim = typeToVisit.dimensions();
        if (dim > 0) {
            leafType = typeToVisit.leafComponentType();
            switch (leafType.id) {
            case TypeIds.T_JavaLangObject:
                if (dim > 1) { // Object[][] supertype is Object[]
                    TypeBinding elementType = ((ArrayBinding) typeToVisit).elementsType();
                    if (!typesToVisit.contains(elementType)) {
                        typesToVisit.add(elementType);
                        max++;
                    }
                    continue;
                }
                //$FALL-THROUGH$
            case TypeIds.T_byte:
            case TypeIds.T_short:
            case TypeIds.T_char:
            case TypeIds.T_boolean:
            case TypeIds.T_int:
            case TypeIds.T_long:
            case TypeIds.T_float:
            case TypeIds.T_double:
                TypeBinding superType = getJavaIoSerializable();
                if (!typesToVisit.contains(superType)) {
                    typesToVisit.add(superType);
                    max++;
                }
                superType = getJavaLangCloneable();
                if (!typesToVisit.contains(superType)) {
                    typesToVisit.add(superType);
                    max++;
                }
                superType = getJavaLangObject();
                if (!typesToVisit.contains(superType)) {
                    typesToVisit.add(superType);
                    max++;
                }
                continue;

            default:
            }
            typeToVisit = leafType;
        }
        currentType = (ReferenceBinding) typeToVisit;
        if (currentType.isCapture()) {
            TypeBinding firstBound = ((CaptureBinding) currentType).firstBound;
            if (firstBound != null && firstBound.isArrayType()) {
                TypeBinding superType = dim == 0 ? firstBound
                        : (TypeBinding) environment().createArrayType(firstBound, dim); // recreate array if needed
                if (!typesToVisit.contains(superType)) {
                    typesToVisit.add(superType);
                    max++;
                    TypeBinding superTypeErasure = (firstBound.isTypeVariable()
                            || firstBound.isWildcard() /*&& !itsInterface.isCapture()*/) ? superType
                                    : superType.erasure();
                    if (superTypeErasure != superType) {
                        allInvocations.put(superTypeErasure, superType);
                    }
                }
                continue;
            }
        }
        // inject super interfaces prior to superclass
        ReferenceBinding[] itsInterfaces = currentType.superInterfaces();
        if (itsInterfaces != null) { // can be null during code assist operations that use LookupEnvironment.completeTypeBindings(parsedUnit, buildFieldsAndMethods)
            for (int j = 0, count = itsInterfaces.length; j < count; j++) {
                TypeBinding itsInterface = itsInterfaces[j];
                TypeBinding superType = dim == 0 ? itsInterface
                        : (TypeBinding) environment().createArrayType(itsInterface, dim); // recreate array if needed
                if (!typesToVisit.contains(superType)) {
                    typesToVisit.add(superType);
                    max++;
                    TypeBinding superTypeErasure = (itsInterface.isTypeVariable()
                            || itsInterface.isWildcard() /*&& !itsInterface.isCapture()*/) ? superType
                                    : superType.erasure();
                    if (superTypeErasure != superType) {
                        allInvocations.put(superTypeErasure, superType);
                    }
                }
            }
        }
        TypeBinding itsSuperclass = currentType.superclass();
        if (itsSuperclass != null) {
            TypeBinding superType = dim == 0 ? itsSuperclass
                    : (TypeBinding) environment().createArrayType(itsSuperclass, dim); // recreate array if needed
            if (!typesToVisit.contains(superType)) {
                typesToVisit.add(superType);
                max++;
                TypeBinding superTypeErasure = (itsSuperclass.isTypeVariable()
                        || itsSuperclass.isWildcard() /*&& !itsSuperclass.isCapture()*/) ? superType
                                : superType.erasure();
                if (superTypeErasure != superType) {
                    allInvocations.put(superTypeErasure, superType);
                }
            }
        }
    }
    int superLength = typesToVisit.size();
    TypeBinding[] erasedSuperTypes = new TypeBinding[superLength];
    int rank = 0;
    for (Iterator iter = typesToVisit.iterator(); iter.hasNext();) {
        TypeBinding type = (TypeBinding) iter.next();
        leafType = type.leafComponentType();
        erasedSuperTypes[rank++] = (leafType.isTypeVariable()
                || leafType.isWildcard() /*&& !leafType.isCapture()*/) ? type : type.erasure();
    }
    // intersecting first type supertypes with other types' ones, nullifying non matching supertypes
    int remaining = superLength;
    nextOtherType: for (int i = indexOfFirst + 1; i < length; i++) {
        TypeBinding otherType = types[i];
        if (otherType == null)
            continue nextOtherType;
        if (otherType.isArrayType()) {
            nextSuperType: for (int j = 0; j < superLength; j++) {
                TypeBinding erasedSuperType = erasedSuperTypes[j];
                if (erasedSuperType == null || erasedSuperType == otherType)
                    continue nextSuperType;
                TypeBinding match;
                if ((match = otherType.findSuperTypeOriginatingFrom(erasedSuperType)) == null) {
                    erasedSuperTypes[j] = null;
                    if (--remaining == 0)
                        return null;
                    continue nextSuperType;
                }
                // record invocation
                Object invocationData = allInvocations.get(erasedSuperType);
                if (invocationData == null) {
                    allInvocations.put(erasedSuperType, match); // no array for singleton
                } else if (invocationData instanceof TypeBinding) {
                    if (match != invocationData) {
                        // using an array to record invocations in order (188103)
                        TypeBinding[] someInvocations = { (TypeBinding) invocationData, match, };
                        allInvocations.put(erasedSuperType, someInvocations);
                    }
                } else { // using an array to record invocations in order (188103)
                    TypeBinding[] someInvocations = (TypeBinding[]) invocationData;
                    checkExisting: {
                        int invocLength = someInvocations.length;
                        for (int k = 0; k < invocLength; k++) {
                            if (someInvocations[k] == match)
                                break checkExisting;
                        }
                        System.arraycopy(someInvocations, 0, someInvocations = new TypeBinding[invocLength + 1],
                                0, invocLength);
                        allInvocations.put(erasedSuperType, someInvocations);
                        someInvocations[invocLength] = match;
                    }
                }
            }
            continue nextOtherType;
        }
        nextSuperType: for (int j = 0; j < superLength; j++) {
            TypeBinding erasedSuperType = erasedSuperTypes[j];
            if (erasedSuperType == null)
                continue nextSuperType;
            TypeBinding match;
            if (erasedSuperType == otherType
                    || erasedSuperType.id == TypeIds.T_JavaLangObject && otherType.isInterface()) {
                match = erasedSuperType;
            } else {
                if (erasedSuperType.isArrayType()) {
                    match = null;
                } else {
                    match = otherType.findSuperTypeOriginatingFrom(erasedSuperType);
                }
                if (match == null) { // incompatible super type
                    erasedSuperTypes[j] = null;
                    if (--remaining == 0)
                        return null;
                    continue nextSuperType;
                }
            }
            // record invocation
            Object invocationData = allInvocations.get(erasedSuperType);
            if (invocationData == null) {
                allInvocations.put(erasedSuperType, match); // no array for singleton
            } else if (invocationData instanceof TypeBinding) {
                if (match != invocationData) {
                    // using an array to record invocations in order (188103)
                    TypeBinding[] someInvocations = { (TypeBinding) invocationData, match, };
                    allInvocations.put(erasedSuperType, someInvocations);
                }
            } else { // using an array to record invocations in order (188103)
                TypeBinding[] someInvocations = (TypeBinding[]) invocationData;
                checkExisting: {
                    int invocLength = someInvocations.length;
                    for (int k = 0; k < invocLength; k++) {
                        if (someInvocations[k] == match)
                            break checkExisting;
                    }
                    System.arraycopy(someInvocations, 0, someInvocations = new TypeBinding[invocLength + 1], 0,
                            invocLength);
                    allInvocations.put(erasedSuperType, someInvocations);
                    someInvocations[invocLength] = match;
                }
            }
        }
    }
    // eliminate non minimal super types
    if (remaining > 1) {
        nextType: for (int i = 0; i < superLength; i++) {
            TypeBinding erasedSuperType = erasedSuperTypes[i];
            if (erasedSuperType == null)
                continue nextType;
            nextOtherType: for (int j = 0; j < superLength; j++) {
                if (i == j)
                    continue nextOtherType;
                TypeBinding otherType = erasedSuperTypes[j];
                if (otherType == null)
                    continue nextOtherType;
                if (erasedSuperType instanceof ReferenceBinding) {
                    if (otherType.id == TypeIds.T_JavaLangObject && erasedSuperType.isInterface())
                        continue nextOtherType; // keep Object for an interface
                    if (erasedSuperType.findSuperTypeOriginatingFrom(otherType) != null) {
                        erasedSuperTypes[j] = null; // discard non minimal supertype
                        remaining--;
                    }
                } else if (erasedSuperType.isArrayType()) {
                    if (otherType.isArrayType() // keep Object[...] for an interface array (same dimensions)
                            && otherType.leafComponentType().id == TypeIds.T_JavaLangObject
                            && otherType.dimensions() == erasedSuperType.dimensions()
                            && erasedSuperType.leafComponentType().isInterface())
                        continue nextOtherType;
                    if (erasedSuperType.findSuperTypeOriginatingFrom(otherType) != null) {
                        erasedSuperTypes[j] = null; // discard non minimal supertype
                        remaining--;
                    }
                }
            }
        }
    }
    return erasedSuperTypes;
}

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

License:Open Source License

/**
 * Returns true if a type is identical to another one,
 * or for generic types, true if compared to its raw type.
 *///from  w  w w.  jav a  2s  . c  o m
public boolean isEquivalentTo(TypeBinding otherType) {

    if (this == otherType)
        return true;
    if (otherType == null)
        return false;
    switch (otherType.kind()) {

    case Binding.WILDCARD_TYPE:
    case Binding.INTERSECTION_TYPE:
        return ((WildcardBinding) otherType).boundCheck(this);

    case Binding.PARAMETERIZED_TYPE:
        if ((otherType.tagBits & TagBits.HasDirectWildcard) == 0
                && (!isMemberType() || !otherType.isMemberType()))
            return false; // should have been identical
        ParameterizedTypeBinding otherParamType = (ParameterizedTypeBinding) otherType;
        if (this != otherParamType.genericType())
            return false;
        if (!isStatic()) { // static member types do not compare their enclosing
            ReferenceBinding enclosing = enclosingType();
            if (enclosing != null) {
                ReferenceBinding otherEnclosing = otherParamType.enclosingType();
                if (otherEnclosing == null)
                    return false;
                if ((otherEnclosing.tagBits & TagBits.HasDirectWildcard) == 0) {
                    if (enclosing != otherEnclosing)
                        return false;
                } else {
                    if (!enclosing.isEquivalentTo(otherParamType.enclosingType()))
                        return false;
                }
            }
        }
        int length = this.typeVariables == null ? 0 : this.typeVariables.length;
        TypeBinding[] otherArguments = otherParamType.arguments;
        int otherLength = otherArguments == null ? 0 : otherArguments.length;
        if (otherLength != length)
            return false;
        for (int i = 0; i < length; i++)
            if (!this.typeVariables[i].isTypeArgumentContainedBy(otherArguments[i]))
                return false;
        return true;

    case Binding.RAW_TYPE:
        return otherType.erasure() == this;
    }
    return false;
}