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

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

Introduction

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

Prototype

TypeVariableBinding[] NO_TYPE_VARIABLES

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

Click Source Link

Usage

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

License:Open Source License

boolean areParametersEqual(MethodBinding one, MethodBinding two) {
    TypeBinding[] oneArgs = one.parameters;
    TypeBinding[] twoArgs = two.parameters;
    if (oneArgs == twoArgs)
        return true;

    int length = oneArgs.length;
    if (length != twoArgs.length)
        return false;

    // methods with raw parameters are considered equal to inherited methods
    // with parameterized parameters for backwards compatibility, need a more complex check
    int i;//from  ww w  . j a  v a2  s.co  m
    foundRAW: for (i = 0; i < length; i++) {
        if (!areTypesEqual(oneArgs[i], twoArgs[i])) {
            if (oneArgs[i].leafComponentType().isRawType()) {
                if (oneArgs[i].dimensions() == twoArgs[i].dimensions()
                        && oneArgs[i].leafComponentType().isEquivalentTo(twoArgs[i].leafComponentType())) {
                    // raw mode does not apply if the method defines its own type variables
                    if (one.typeVariables != Binding.NO_TYPE_VARIABLES)
                        return false;
                    // one parameter type is raw, hence all parameters types must be raw or non generic
                    // otherwise we have a mismatch check backwards
                    for (int j = 0; j < i; j++)
                        if (oneArgs[j].leafComponentType().isParameterizedTypeWithActualArguments())
                            return false;
                    // switch to all raw mode
                    break foundRAW;
                }
            }
            return false;
        }
    }
    // all raw mode for remaining parameters (if any)
    for (i++; i < length; i++) {
        if (!areTypesEqual(oneArgs[i], twoArgs[i])) {
            if (oneArgs[i].leafComponentType().isRawType())
                if (oneArgs[i].dimensions() == twoArgs[i].dimensions()
                        && oneArgs[i].leafComponentType().isEquivalentTo(twoArgs[i].leafComponentType()))
                    continue;
            return false;
        } else if (oneArgs[i].leafComponentType().isParameterizedTypeWithActualArguments()) {
            return false; // no remaining parameter can be a Parameterized type (if one has been converted then all RAW types must be converted)
        }
    }
    return true;
}

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

License:Open Source License

boolean doTypeVariablesClash(MethodBinding one, MethodBinding substituteTwo) {
    // one has type variables and substituteTwo did not pass bounds check in computeSubstituteMethod()
    return one.typeVariables != Binding.NO_TYPE_VARIABLES
            && !(substituteTwo instanceof ParameterizedGenericMethodBinding);
}

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

License:Open Source License

boolean isSubstituteParameterSubsignature(MethodBinding method, MethodBinding substituteMethod) {
    if (!areParametersEqual(method, substituteMethod)) {
        // method can still override substituteMethod in cases like :
        // <U extends Number> void c(U u) {}
        // @Override void c(Number n) {}
        // but method cannot have a "generic-enabled" parameter type
        if (substituteMethod.hasSubstitutedParameters() && method.areParameterErasuresEqual(substituteMethod))
            return method.typeVariables == Binding.NO_TYPE_VARIABLES && !hasGenericParameter(method);

        // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=279836
        if (method.declaringClass.isRawType() && substituteMethod.declaringClass.isRawType())
            if (method.hasSubstitutedParameters() && substituteMethod.hasSubstitutedParameters())
                return areMethodsCompatible(method, substituteMethod);

        return false;
    }// w ww .j  a  va  2s. com

    if (substituteMethod instanceof ParameterizedGenericMethodBinding) {
        if (method.typeVariables != Binding.NO_TYPE_VARIABLES)
            return !((ParameterizedGenericMethodBinding) substituteMethod).isRaw;
        // since substituteMethod has substituted type variables, method cannot have a generic signature AND no variables -> its a name clash if it does
        return !hasGenericParameter(method);
    }

    // if method has its own variables, then substituteMethod failed bounds check in computeSubstituteMethod()
    return method.typeVariables == Binding.NO_TYPE_VARIABLES;
}

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

License:Open Source License

boolean isUnsafeReturnTypeOverride(MethodBinding currentMethod, MethodBinding inheritedMethod) {
    // called when currentMethod's return type is NOT compatible with inheritedMethod's return type

    // JLS 3 8.4.5: more are accepted, with an unchecked conversion
    if (currentMethod.returnType == inheritedMethod.returnType.erasure()) {
        TypeBinding[] currentParams = currentMethod.parameters;
        TypeBinding[] inheritedParams = inheritedMethod.parameters;
        for (int i = 0, l = currentParams.length; i < l; i++)
            if (!areTypesEqual(currentParams[i], inheritedParams[i]))
                return true;
    }/*w w w .j  ava  2  s  . c om*/
    if (currentMethod.typeVariables == Binding.NO_TYPE_VARIABLES
            && inheritedMethod.original().typeVariables != Binding.NO_TYPE_VARIABLES && currentMethod.returnType
                    .erasure().findSuperTypeOriginatingFrom(inheritedMethod.returnType.erasure()) != null) {
        return true;
    }
    return false;
}

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

License:Open Source License

public char[] computeGenericTypeSignature(TypeVariableBinding[] typeVariables) {

    boolean isMemberOfGeneric = isMemberType()
            && (enclosingType().modifiers & ExtraCompilerModifiers.AccGenericSignature) != 0;
    if (typeVariables == Binding.NO_TYPE_VARIABLES && !isMemberOfGeneric) {
        return signature();
    }/*from   www  .  j  av  a2  s. c  o m*/
    StringBuffer sig = new StringBuffer(10);
    if (isMemberOfGeneric) {
        char[] typeSig = enclosingType().genericTypeSignature();
        sig.append(typeSig, 0, typeSig.length - 1); // copy all but trailing semicolon
        sig.append('.'); // NOTE: cannot override trailing ';' with '.' in enclosing signature, since shared char[]
        sig.append(this.sourceName);
    } else {
        char[] typeSig = signature();
        sig.append(typeSig, 0, typeSig.length - 1); // copy all but trailing semicolon
    }
    if (typeVariables == Binding.NO_TYPE_VARIABLES) {
        sig.append(';');
    } else {
        sig.append('<');
        for (int i = 0, length = typeVariables.length; i < length; i++) {
            sig.append(typeVariables[i].genericTypeSignature());
        }
        sig.append(">;"); //$NON-NLS-1$
    }
    int sigLength = sig.length();
    char[] result = new char[sigLength];
    sig.getChars(0, sigLength, result, 0);
    return result;
}

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

License:Open Source License

/**
 * Answer the receiver's signature./*from w  w  w  .j av  a  2 s  . com*/
 *
 * NOTE: This method should only be used during/after code gen.
 */
public char[] readableName() /*java.lang.Object,  p.X<T> */ {
    char[] readableName;
    if (isMemberType()) {
        readableName = CharOperation.concat(enclosingType().readableName(), this.sourceName, '.');
    } else {
        readableName = CharOperation.concatWith(this.compoundName, '.');
    }
    TypeVariableBinding[] typeVars;
    if ((typeVars = typeVariables()) != Binding.NO_TYPE_VARIABLES) {
        StringBuffer nameBuffer = new StringBuffer(10);
        nameBuffer.append(readableName).append('<');
        for (int i = 0, length = typeVars.length; i < length; i++) {
            if (i > 0)
                nameBuffer.append(',');
            nameBuffer.append(typeVars[i].readableName());
        }
        nameBuffer.append('>');
        int nameLength = nameBuffer.length();
        readableName = new char[nameLength];
        nameBuffer.getChars(0, nameLength, readableName, 0);
    }
    return readableName;
}

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

License:Open Source License

public char[] shortReadableName() /*Object*/ {
    char[] shortReadableName;
    if (isMemberType()) {
        shortReadableName = CharOperation.concat(enclosingType().shortReadableName(), this.sourceName, '.');
    } else {//from w ww.  j ava 2s  . c  om
        shortReadableName = this.sourceName;
    }
    TypeVariableBinding[] typeVars;
    if ((typeVars = typeVariables()) != Binding.NO_TYPE_VARIABLES) {
        StringBuffer nameBuffer = new StringBuffer(10);
        nameBuffer.append(shortReadableName).append('<');
        for (int i = 0, length = typeVars.length; i < length; i++) {
            if (i > 0)
                nameBuffer.append(',');
            nameBuffer.append(typeVars[i].shortReadableName());
        }
        nameBuffer.append('>');
        int nameLength = nameBuffer.length();
        shortReadableName = new char[nameLength];
        nameBuffer.getChars(0, nameLength, shortReadableName, 0);
    }
    return shortReadableName;
}

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

License:Open Source License

/**
 * Internal use only/*from w  w w  .  j  av a2s  .c o  m*/
 * Given a method, returns null if arguments cannot be converted to parameters.
 * Will answer a substituted method in case the method was generic and type inference got triggered;
 * in case the method was originally compatible, then simply answer it back.
 */
protected final MethodBinding computeCompatibleMethod(MethodBinding method, TypeBinding[] arguments,
        InvocationSite invocationSite) {
    TypeBinding[] genericTypeArguments = invocationSite.genericTypeArguments();
    TypeBinding[] parameters = method.parameters;
    TypeVariableBinding[] typeVariables = method.typeVariables;
    if (parameters == arguments && (method.returnType.tagBits & TagBits.HasTypeVariable) == 0
            && genericTypeArguments == null && typeVariables == Binding.NO_TYPE_VARIABLES)
        return method;

    int argLength = arguments.length;
    int paramLength = parameters.length;
    boolean isVarArgs = method.isVarargs();
    if (argLength != paramLength)
        if (!isVarArgs || argLength < paramLength - 1)
            return null; // incompatible

    // https://bugs.eclipse.org/bugs/show_bug.cgi?id=330435, inference should kick in only at source 1.5+
    if (typeVariables != Binding.NO_TYPE_VARIABLES
            && compilerOptions().sourceLevel >= ClassFileConstants.JDK1_5) { // generic method
        TypeBinding[] newArgs = null;
        for (int i = 0; i < argLength; i++) {
            TypeBinding param = i < paramLength ? parameters[i] : parameters[paramLength - 1];
            if (arguments[i].isBaseType() != param.isBaseType()) {
                if (newArgs == null) {
                    newArgs = new TypeBinding[argLength];
                    System.arraycopy(arguments, 0, newArgs, 0, argLength);
                }
                newArgs[i] = environment().computeBoxingType(arguments[i]);
            }
        }
        if (newArgs != null)
            arguments = newArgs;
        method = ParameterizedGenericMethodBinding.computeCompatibleMethod(method, arguments, this,
                invocationSite);
        if (method == null)
            return null; // incompatible
        if (!method.isValidBinding())
            return method; // bound check issue is taking precedence
    } else if (genericTypeArguments != null && compilerOptions().complianceLevel < ClassFileConstants.JDK1_7) {
        if (method instanceof ParameterizedGenericMethodBinding) {
            if (!((ParameterizedGenericMethodBinding) method).wasInferred)
                // attempt to invoke generic method of raw type with type hints <String>foo()
                return new ProblemMethodBinding(method, method.selector, genericTypeArguments,
                        ProblemReasons.TypeArgumentsForRawGenericMethod);
        } else if (!method.isOverriding() || !isOverriddenMethodGeneric(method)) {
            return new ProblemMethodBinding(method, method.selector, genericTypeArguments,
                    ProblemReasons.TypeParameterArityMismatch);
        }
    }

    if (parameterCompatibilityLevel(method, arguments) > NOT_COMPATIBLE) {
        if ((method.tagBits & TagBits.AnnotationPolymorphicSignature) != 0) {
            // generate polymorphic method
            return this.environment().createPolymorphicMethod(method, arguments);
        }
        return method;
    }
    // if method is generic and type arguments have been supplied, only then answer a problem 
    // of ParameterizedMethodTypeMismatch, else a non-generic method was invoked using type arguments
    // in which case this problem category will be bogus
    if (genericTypeArguments != null && typeVariables != Binding.NO_TYPE_VARIABLES)
        return new ProblemMethodBinding(method, method.selector, arguments,
                ProblemReasons.ParameterizedMethodTypeMismatch);
    return null; // incompatible
}

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

License:Open Source License

public TypeVariableBinding[] createTypeVariables(TypeParameter[] typeParameters, Binding declaringElement) {
    // https://bugs.eclipse.org/bugs/show_bug.cgi?id=324850, If they exist at all, process type parameters irrespective of source level.
    if (typeParameters == null || typeParameters.length == 0)
        return Binding.NO_TYPE_VARIABLES;

    PackageBinding unitPackage = compilationUnitScope().fPackage;
    int length = typeParameters.length;
    TypeVariableBinding[] typeVariableBindings = new TypeVariableBinding[length];
    int count = 0;
    for (int i = 0; i < length; i++) {
        TypeParameter typeParameter = typeParameters[i];
        TypeVariableBinding parameterBinding = new TypeVariableBinding(typeParameter.name, declaringElement, i,
                environment());/*from w w  w  .  j av a  2 s.com*/
        parameterBinding.fPackage = unitPackage;
        typeParameter.binding = parameterBinding;

        // detect duplicates, but keep each variable to reduce secondary errors with instantiating this generic type (assume number of variables is correct)
        for (int j = 0; j < count; j++) {
            TypeVariableBinding knownVar = typeVariableBindings[j];
            if (CharOperation.equals(knownVar.sourceName, typeParameter.name))
                problemReporter().duplicateTypeParameterInType(typeParameter);
        }
        typeVariableBindings[count++] = parameterBinding;
        //            TODO should offer warnings to inform about hiding declaring, enclosing or member types
        //            ReferenceBinding type = sourceType;
        //            // check that the member does not conflict with an enclosing type
        //            do {
        //               if (CharOperation.equals(type.sourceName, memberContext.name)) {
        //                  problemReporter().hidingEnclosingType(memberContext);
        //                  continue nextParameter;
        //               }
        //               type = type.enclosingType();
        //            } while (type != null);
        //            // check that the member type does not conflict with another sibling member type
        //            for (int j = 0; j < i; j++) {
        //               if (CharOperation.equals(referenceContext.memberTypes[j].name, memberContext.name)) {
        //                  problemReporter().duplicateNestedType(memberContext);
        //                  continue nextParameter;
        //               }
        //            }
    }
    if (count != length)
        System.arraycopy(typeVariableBindings, 0, typeVariableBindings = new TypeVariableBinding[count], 0,
                count);
    return typeVariableBindings;
}

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

License:Open Source License

public MethodBinding findExactMethod(ReferenceBinding receiverType, char[] selector,
        TypeBinding[] argumentTypes, InvocationSite invocationSite) {
    CompilationUnitScope unitScope = compilationUnitScope();
    unitScope.recordTypeReferences(argumentTypes);
    MethodBinding exactMethod = receiverType.getExactMethod(selector, argumentTypes, unitScope);
    if (exactMethod != null && exactMethod.typeVariables == Binding.NO_TYPE_VARIABLES
            && !exactMethod.isBridge()) {
        // in >= 1.5 mode, ensure the exactMatch did not match raw types
        if (compilerOptions().sourceLevel >= ClassFileConstants.JDK1_5)
            for (int i = argumentTypes.length; --i >= 0;)
                if (isPossibleSubtypeOfRawType(argumentTypes[i]))
                    return null;
        // must find both methods for this case: <S extends A> void foo() {}  and  <N extends B> N foo() { return null; }
        // or find an inherited method when the exact match is to a bridge method
        unitScope.recordTypeReferences(exactMethod.thrownExceptions);
        if (exactMethod.isAbstract() && exactMethod.thrownExceptions != Binding.NO_EXCEPTIONS)
            return null; // may need to merge exceptions with interface method
        // special treatment for Object.getClass() in 1.5 mode (substitute parameterized return type)
        if (receiverType.isInterface() || exactMethod.canBeSeenBy(receiverType, invocationSite, this)) {
            if (argumentTypes == Binding.NO_PARAMETERS && CharOperation.equals(selector, TypeConstants.GETCLASS)
                    && exactMethod.returnType.isParameterizedType()/*1.5*/) {
                return environment().createGetClassMethod(receiverType, exactMethod, this);
            }// w  w  w. ja  va2  s  .  co  m
            // targeting a generic method could find an exact match with variable return type
            if (invocationSite.genericTypeArguments() != null) {
                exactMethod = computeCompatibleMethod(exactMethod, argumentTypes, invocationSite);
            }
            return exactMethod;
        }
    }
    return null;
}