Example usage for org.eclipse.jdt.internal.compiler.lookup ReferenceBinding isHierarchyBeingConnected

List of usage examples for org.eclipse.jdt.internal.compiler.lookup ReferenceBinding isHierarchyBeingConnected

Introduction

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

Prototype

public boolean isHierarchyBeingConnected() 

Source Link

Document

Returns true if the type hierarchy is being connected

Usage

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

License:Open Source License

public ReferenceBinding findMemberType(char[] typeName, ReferenceBinding enclosingType) {
    if ((enclosingType.tagBits & TagBits.HasNoMemberTypes) != 0)
        return null; // know it has no member types (nor inherited member types)

    ReferenceBinding enclosingSourceType = enclosingSourceType();
    PackageBinding currentPackage = getCurrentPackage();
    CompilationUnitScope unitScope = compilationUnitScope();
    unitScope.recordReference(enclosingType, typeName);
    ReferenceBinding memberType = enclosingType.getMemberType(typeName);
    if (memberType != null) {
        unitScope.recordTypeReference(memberType);
        if (enclosingSourceType == null || (this.parent == unitScope
                && (enclosingSourceType.tagBits & TagBits.TypeVariablesAreConnected) == 0)
                        ? memberType.canBeSeenBy(currentPackage)
                        : memberType.canBeSeenBy(enclosingType, enclosingSourceType))
            return memberType;
        return new ProblemReferenceBinding(new char[][] { typeName }, memberType, ProblemReasons.NotVisible);
    }/*from  w  ww.j a  v a  2 s .co  m*/

    // collect all superinterfaces of receiverType until the memberType is found in a supertype
    ReferenceBinding currentType = enclosingType;
    ReferenceBinding[] interfacesToVisit = null;
    int nextPosition = 0;
    ReferenceBinding visibleMemberType = null;
    boolean keepLooking = true;
    ReferenceBinding notVisible = null;
    // we could hold onto the not visible field for extra error reporting
    while (keepLooking) {
        ReferenceBinding[] itsInterfaces = currentType.superInterfaces();
        if (itsInterfaces == null) { // needed for statically imported types which don't know their hierarchy yet
            ReferenceBinding sourceType = currentType.isParameterizedType()
                    ? ((ParameterizedTypeBinding) currentType).genericType()
                    : currentType;
            if (sourceType.isHierarchyBeingConnected())
                return null; // looking for an undefined member type in its own superclass ref
            ((SourceTypeBinding) sourceType).scope.connectTypeHierarchy();
            itsInterfaces = currentType.superInterfaces();
        }
        if (itsInterfaces != null && itsInterfaces != Binding.NO_SUPERINTERFACES) {
            if (interfacesToVisit == null) {
                interfacesToVisit = itsInterfaces;
                nextPosition = interfacesToVisit.length;
            } else {
                int itsLength = itsInterfaces.length;
                if (nextPosition + itsLength >= interfacesToVisit.length)
                    System.arraycopy(interfacesToVisit, 0,
                            interfacesToVisit = new ReferenceBinding[nextPosition + itsLength + 5], 0,
                            nextPosition);
                nextInterface: for (int a = 0; a < itsLength; a++) {
                    ReferenceBinding next = itsInterfaces[a];
                    for (int b = 0; b < nextPosition; b++)
                        if (next == interfacesToVisit[b])
                            continue nextInterface;
                    interfacesToVisit[nextPosition++] = next;
                }
            }
        }
        if ((currentType = currentType.superclass()) == null)
            break;

        unitScope.recordReference(currentType, typeName);
        if ((memberType = currentType.getMemberType(typeName)) != null) {
            unitScope.recordTypeReference(memberType);
            keepLooking = false;
            if (enclosingSourceType == null ? memberType.canBeSeenBy(currentPackage)
                    : memberType.canBeSeenBy(enclosingType, enclosingSourceType)) {
                if (visibleMemberType == null)
                    visibleMemberType = memberType;
                else
                    return new ProblemReferenceBinding(new char[][] { typeName }, visibleMemberType,
                            ProblemReasons.Ambiguous);
            } else {
                notVisible = memberType;
            }
        }
    }
    // walk all visible interfaces to find ambiguous references
    if (interfacesToVisit != null) {
        ProblemReferenceBinding ambiguous = null;
        done: for (int i = 0; i < nextPosition; i++) {
            ReferenceBinding anInterface = interfacesToVisit[i];
            unitScope.recordReference(anInterface, typeName);
            if ((memberType = anInterface.getMemberType(typeName)) != null) {
                unitScope.recordTypeReference(memberType);
                if (visibleMemberType == null) {
                    visibleMemberType = memberType;
                } else {
                    ambiguous = new ProblemReferenceBinding(new char[][] { typeName }, visibleMemberType,
                            ProblemReasons.Ambiguous);
                    break done;
                }
            } else {
                ReferenceBinding[] itsInterfaces = anInterface.superInterfaces();
                if (itsInterfaces != null && itsInterfaces != Binding.NO_SUPERINTERFACES) {
                    int itsLength = itsInterfaces.length;
                    if (nextPosition + itsLength >= interfacesToVisit.length)
                        System.arraycopy(interfacesToVisit, 0,
                                interfacesToVisit = new ReferenceBinding[nextPosition + itsLength + 5], 0,
                                nextPosition);
                    nextInterface: for (int a = 0; a < itsLength; a++) {
                        ReferenceBinding next = itsInterfaces[a];
                        for (int b = 0; b < nextPosition; b++)
                            if (next == interfacesToVisit[b])
                                continue nextInterface;
                        interfacesToVisit[nextPosition++] = next;
                    }
                }
            }
        }
        if (ambiguous != null)
            return ambiguous;
    }
    if (visibleMemberType != null)
        return visibleMemberType;
    if (notVisible != null)
        return new ProblemReferenceBinding(new char[][] { typeName }, notVisible, ProblemReasons.NotVisible);
    return null;
}