Example usage for org.eclipse.jdt.internal.compiler.lookup ProblemReasons ReceiverTypeNotVisible

List of usage examples for org.eclipse.jdt.internal.compiler.lookup ProblemReasons ReceiverTypeNotVisible

Introduction

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

Prototype

int ReceiverTypeNotVisible

To view the source code for org.eclipse.jdt.internal.compiler.lookup ProblemReasons ReceiverTypeNotVisible.

Click Source Link

Usage

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

License:Open Source License

public FieldBinding findField(TypeBinding receiverType, char[] fieldName, InvocationSite invocationSite,
        boolean needResolve, boolean invisibleFieldsOk) {

    CompilationUnitScope unitScope = compilationUnitScope();
    unitScope.recordTypeReference(receiverType);

    checkArrayField: {//from w  w  w  . j a v a  2  s. com
        TypeBinding leafType;
        switch (receiverType.kind()) {
        case Binding.BASE_TYPE:
            return null;
        case Binding.WILDCARD_TYPE:
        case Binding.INTERSECTION_TYPE:
        case Binding.TYPE_PARAMETER: // capture
            TypeBinding receiverErasure = receiverType.erasure();
            if (!receiverErasure.isArrayType())
                break checkArrayField;
            leafType = receiverErasure.leafComponentType();
            break;
        case Binding.ARRAY_TYPE:
            leafType = receiverType.leafComponentType();
            break;
        default:
            break checkArrayField;
        }
        if (leafType instanceof ReferenceBinding)
            if (!((ReferenceBinding) leafType).canBeSeenBy(this))
                return new ProblemFieldBinding((ReferenceBinding) leafType, fieldName,
                        ProblemReasons.ReceiverTypeNotVisible);
        if (CharOperation.equals(fieldName, TypeConstants.LENGTH)) {
            if ((leafType.tagBits & TagBits.HasMissingType) != 0) {
                return new ProblemFieldBinding(ArrayBinding.ArrayLength, null, fieldName,
                        ProblemReasons.NotFound);
            }
            return ArrayBinding.ArrayLength;
        }
        return null;
    }

    ReferenceBinding currentType = (ReferenceBinding) receiverType;
    if (!currentType.canBeSeenBy(this))
        return new ProblemFieldBinding(currentType, fieldName, ProblemReasons.ReceiverTypeNotVisible);

    currentType.initializeForStaticImports();
    FieldBinding field = currentType.getField(fieldName, needResolve);
    // https://bugs.eclipse.org/bugs/show_bug.cgi?id=316456
    boolean insideTypeAnnotations = this instanceof MethodScope && ((MethodScope) this).insideTypeAnnotation;
    if (field != null) {
        if (invisibleFieldsOk) {
            return field;
        }
        if (invocationSite == null || insideTypeAnnotations ? field.canBeSeenBy(getCurrentPackage())
                : field.canBeSeenBy(currentType, invocationSite, this))
            return field;
        return new ProblemFieldBinding(field /* closest match*/, field.declaringClass, fieldName,
                ProblemReasons.NotVisible);
    }
    // collect all superinterfaces of receiverType until the field is found in a supertype
    ReferenceBinding[] interfacesToVisit = null;
    int nextPosition = 0;
    FieldBinding visibleField = null;
    boolean keepLooking = true;
    FieldBinding notVisibleField = null;
    // we could hold onto the not visible field for extra error reporting
    while (keepLooking) {
        ReferenceBinding[] 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.recordTypeReference(currentType);
        currentType.initializeForStaticImports();
        currentType = (ReferenceBinding) currentType.capture(this,
                invocationSite == null ? 0 : invocationSite.sourceEnd());
        if ((field = currentType.getField(fieldName, needResolve)) != null) {
            if (invisibleFieldsOk) {
                return field;
            }
            keepLooking = false;
            if (field.canBeSeenBy(receiverType, invocationSite, this)) {
                if (visibleField == null)
                    visibleField = field;
                else
                    return new ProblemFieldBinding(visibleField /* closest match*/, visibleField.declaringClass,
                            fieldName, ProblemReasons.Ambiguous);
            } else {
                if (notVisibleField == null)
                    notVisibleField = field;
            }
        }
    }

    // walk all visible interfaces to find ambiguous references
    if (interfacesToVisit != null) {
        ProblemFieldBinding ambiguous = null;
        done: for (int i = 0; i < nextPosition; i++) {
            ReferenceBinding anInterface = interfacesToVisit[i];
            unitScope.recordTypeReference(anInterface);
            // no need to capture rcv interface, since member field is going to be static anyway
            if ((field = anInterface.getField(fieldName, true /*resolve*/)) != null) {
                if (invisibleFieldsOk) {
                    return field;
                }
                if (visibleField == null) {
                    visibleField = field;
                } else {
                    ambiguous = new ProblemFieldBinding(visibleField /* closest match*/,
                            visibleField.declaringClass, fieldName, 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 (visibleField != null)
        return visibleField;
    if (notVisibleField != null) {
        return new ProblemFieldBinding(notVisibleField, currentType, fieldName, ProblemReasons.NotVisible);
    }
    return null;
}

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

License:Open Source License

public MethodBinding findMethodForArray(ArrayBinding receiverType, char[] selector, TypeBinding[] argumentTypes,
        InvocationSite invocationSite) {

    TypeBinding leafType = receiverType.leafComponentType();
    if (leafType instanceof ReferenceBinding) {
        if (!((ReferenceBinding) leafType).canBeSeenBy(this))
            return new ProblemMethodBinding(selector, Binding.NO_PARAMETERS, (ReferenceBinding) leafType,
                    ProblemReasons.ReceiverTypeNotVisible);
    }//w  w w.  j a v a2  s.  com

    ReferenceBinding object = getJavaLangObject();
    MethodBinding methodBinding = object.getExactMethod(selector, argumentTypes, null);
    if (methodBinding != null) {
        // handle the method clone() specially... cannot be protected or throw exceptions
        if (argumentTypes == Binding.NO_PARAMETERS) {
            switch (selector[0]) {
            case 'c':
                if (CharOperation.equals(selector, TypeConstants.CLONE)) {
                    return environment().computeArrayClone(methodBinding);
                }
                break;
            case 'g':
                if (CharOperation.equals(selector, TypeConstants.GETCLASS)
                        && methodBinding.returnType.isParameterizedType()/*1.5*/) {
                    return environment().createGetClassMethod(receiverType, methodBinding, this);
                }
                break;
            }
        }
        if (methodBinding.canBeSeenBy(receiverType, invocationSite, this))
            return methodBinding;
    }
    methodBinding = findMethod(object, selector, argumentTypes, invocationSite);
    if (methodBinding == null)
        return new ProblemMethodBinding(selector, argumentTypes, ProblemReasons.NotFound);
    return methodBinding;
}

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

License:Open Source License

public MethodBinding getMethod(TypeBinding receiverType, char[] selector, TypeBinding[] argumentTypes,
        InvocationSite invocationSite) {
    CompilationUnitScope unitScope = compilationUnitScope();
    LookupEnvironment env = unitScope.environment;
    try {//from   ww  w .  jav  a2 s .  c  o m
        env.missingClassFileLocation = invocationSite;
        switch (receiverType.kind()) {
        case Binding.BASE_TYPE:
            return new ProblemMethodBinding(selector, argumentTypes, ProblemReasons.NotFound);
        case Binding.ARRAY_TYPE:
            unitScope.recordTypeReference(receiverType);
            return findMethodForArray((ArrayBinding) receiverType, selector, argumentTypes, invocationSite);
        }
        unitScope.recordTypeReference(receiverType);

        ReferenceBinding currentType = (ReferenceBinding) receiverType;
        if (!currentType.canBeSeenBy(this))
            return new ProblemMethodBinding(selector, argumentTypes, ProblemReasons.ReceiverTypeNotVisible);

        // retrieve an exact visible match (if possible)
        MethodBinding methodBinding = findExactMethod(currentType, selector, argumentTypes, invocationSite);
        if (methodBinding != null)
            return methodBinding;

        methodBinding = findMethod(currentType, selector, argumentTypes, invocationSite);
        // GROOVY start: give it one more chance as the ast transform may have introduced it
        // is this the right approach?  Requires ast transforms running before this is done
        if (methodBinding == null) {
            methodBinding = oneLastLook(currentType, selector, argumentTypes, invocationSite);
        }
        // GROOVY end
        if (methodBinding == null)
            return new ProblemMethodBinding(selector, argumentTypes, ProblemReasons.NotFound);
        if (!methodBinding.isValidBinding())
            return methodBinding;

        // special treatment for Object.getClass() in 1.5 mode (substitute parameterized return type)
        if (argumentTypes == Binding.NO_PARAMETERS && CharOperation.equals(selector, TypeConstants.GETCLASS)
                && methodBinding.returnType.isParameterizedType()/*1.5*/) {
            return environment().createGetClassMethod(receiverType, methodBinding, this);
        }
        return methodBinding;
    } catch (AbortCompilation e) {
        e.updateContext(invocationSite, referenceCompilationUnit().compilationResult);
        throw e;
    } finally {
        env.missingClassFileLocation = null;
    }
}