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

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

Introduction

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

Prototype

public TypeBinding original() 

Source Link

Document

Returns the orignal generic type instantiated by the receiver type, or itself if not.

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.
 */// w w w.j  a v  a 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.recommenders.rcp.utils.CompilerBindings.java

License:Open Source License

/**
 * TODO nested anonymous types are not resolved correctly. JDT uses line numbers for inner types instead of $1,..,$n
 *//*from   www . ja va 2  s.  c o  m*/
public static Optional<ITypeName> toTypeName(@Nullable TypeBinding binding) {
    if (binding == null) {
        return absent();
    }

    try {
        binding = binding.original();

        char[] signature = binding.signature();
        if (signature == null) {
            return absent();
        }

        final ITypeName result;
        if (isPrimitiveBaseType(binding)) {
            result = VmTypeName.get(String.valueOf(signature));
        } else {
            // Strip of semicolon.
            result = VmTypeName.get(String.valueOf(signature, 0, signature.length - 1));
        }

        return Optional.of(result);
    } catch (final RuntimeException e) {
        return absent();
    }
}