Example usage for org.eclipse.jdt.internal.compiler.lookup TypeBinding isCapture

List of usage examples for org.eclipse.jdt.internal.compiler.lookup TypeBinding isCapture

Introduction

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

Prototype

public boolean isCapture() 

Source Link

Document

Returns true if the type is the capture of some wildcard

Usage

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

License:Open Source License

/**
 * Answer true if the receiver is visible to the receiverType and the invocationType.
 *//*  ww  w.j  ava 2s. c  o  m*/
public final boolean canBeSeenBy(ReferenceBinding receiverType, ReferenceBinding invocationType) {
    if (isPublic())
        return true;

    if (invocationType == this && invocationType == receiverType)
        return true;

    if (isProtected()) {
        // answer true if the invocationType is the declaringClass or they are in the same package
        // OR the invocationType is a subclass of the declaringClass
        //    AND the invocationType is the invocationType or its subclass
        //    OR the type is a static method accessed directly through a type
        //    OR previous assertions are true for one of the enclosing type
        if (invocationType == this)
            return true;
        if (invocationType.fPackage == this.fPackage)
            return true;

        TypeBinding currentType = invocationType.erasure();
        TypeBinding declaringClass = enclosingType().erasure(); // protected types always have an enclosing one
        if (declaringClass == invocationType)
            return true;
        if (declaringClass == null)
            return false; // could be null if incorrect top-level protected type
        //int depth = 0;
        do {
            if (currentType.findSuperTypeOriginatingFrom(declaringClass) != null)
                return true;
            //depth++;
            currentType = currentType.enclosingType();
        } while (currentType != null);
        return false;
    }

    if (isPrivate()) {
        // answer true if the receiverType is the receiver or its enclosingType
        // AND the invocationType and the receiver have a common enclosingType
        receiverCheck: {
            if (!(receiverType == this || receiverType == enclosingType())) {
                // special tolerance for type variable direct bounds, but only if compliance <= 1.6, see: https://bugs.eclipse.org/bugs/show_bug.cgi?id=334622
                if (receiverType.isTypeVariable()) {
                    TypeVariableBinding typeVariable = (TypeVariableBinding) receiverType;
                    if (typeVariable.environment.globalOptions.complianceLevel <= ClassFileConstants.JDK1_6
                            && (typeVariable.isErasureBoundTo(erasure())
                                    || typeVariable.isErasureBoundTo(enclosingType().erasure())))
                        break receiverCheck;
                }
                return false;
            }
        }

        if (invocationType != this) {
            ReferenceBinding outerInvocationType = invocationType;
            ReferenceBinding temp = outerInvocationType.enclosingType();
            while (temp != null) {
                outerInvocationType = temp;
                temp = temp.enclosingType();
            }

            ReferenceBinding outerDeclaringClass = (ReferenceBinding) erasure();
            temp = outerDeclaringClass.enclosingType();
            while (temp != null) {
                outerDeclaringClass = temp;
                temp = temp.enclosingType();
            }
            if (outerInvocationType != outerDeclaringClass)
                return false;
        }
        return true;
    }

    // isDefault()
    if (invocationType.fPackage != this.fPackage)
        return false;

    ReferenceBinding currentType = receiverType;
    TypeBinding originalDeclaringClass = (enclosingType() == null ? this : enclosingType()).original();
    do {
        if (currentType.isCapture()) { // https://bugs.eclipse.org/bugs/show_bug.cgi?id=285002
            if (originalDeclaringClass == currentType.erasure().original())
                return true;
        } else {
            if (originalDeclaringClass == currentType.original())
                return true;
        }
        PackageBinding currentPackage = currentType.fPackage;
        // package could be null for wildcards/intersection types, ignore and recurse in superclass
        if (currentPackage != null && currentPackage != this.fPackage)
            return false;
    } while ((currentType = currentType.superclass()) != null);
    return false;
}

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)
 *//* ww w .  j  a  v a  2s. c  o m*/
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;
    }
}