ReferenceBinding[] superInterfaces = typeParamBinding.superInterfaces();
@Override public TypeBinding clone(TypeBinding enclosingType) { return new TypeVariableBinding(this); } @Override
/** * Returns true if the argument type satisfies all bounds of the type parameter */ public int boundCheck(Substitution substitution, TypeBinding argumentType, Scope scope) { int code = internalBoundCheck(substitution, argumentType, scope); if (code == TypeConstants.MISMATCH) { if (argumentType instanceof TypeVariableBinding && scope != null) { TypeBinding bound = ((TypeVariableBinding)argumentType).firstBound; if (bound instanceof ParameterizedTypeBinding) { int code2 = boundCheck(substitution, bound.capture(scope, -1), scope); // no position needed as this capture will never escape this context return Math.min(code, code2); } } } return code; } private int internalBoundCheck(Substitution substitution, TypeBinding argumentType, Scope scope) {
MethodBinding asRawMethod(LookupEnvironment env) { if (this.typeVariables == Binding.NO_TYPE_VARIABLES) return this; // substitute type arguments with raw types int length = this.typeVariables.length; TypeBinding[] arguments = new TypeBinding[length]; for (int i = 0; i < length; i++) { TypeVariableBinding var = this.typeVariables[i]; if (var.boundsCount() <= 1) { arguments[i] = env.convertToRawType(var.upperBound(), false /*do not force conversion of enclosing types*/); } else { // use an intersection type to retain full bound information if more than 1 bound TypeBinding rawSuperclass = env.convertToRawType(var.superclass(), false); TypeBinding[] itsSuperinterfaces = var.superInterfaces(); int superLength = itsSuperinterfaces.length; TypeBinding[] rawSuperinterfaces = new TypeBinding[superLength]; for (int s = 0; s < superLength; s++) rawSuperinterfaces[s] = env.convertToRawType(itsSuperinterfaces[s], false); arguments[i] = env.createWildcard(null, 0, rawSuperclass, rawSuperinterfaces, org.eclipse.jdt.internal.compiler.ast.Wildcard.EXTENDS); } } return env.createParameterizedGenericMethod(this, arguments); } /* Answer true if the receiver is visible to the type provided by the scope.
public List<TypeBinding> collectMissingTypes(List<TypeBinding> missingTypes) { if ((this.tagBits & TagBits.HasMissingType) != 0) { missingTypes = this.returnType.collectMissingTypes(missingTypes); for (int i = 0, max = this.parameters.length; i < max; i++) { missingTypes = this.parameters[i].collectMissingTypes(missingTypes); } for (int i = 0, max = this.thrownExceptions.length; i < max; i++) { missingTypes = this.thrownExceptions[i].collectMissingTypes(missingTypes); } for (int i = 0, max = this.typeVariables.length; i < max; i++) { TypeVariableBinding variable = this.typeVariables[i]; missingTypes = variable.superclass().collectMissingTypes(missingTypes); ReferenceBinding[] interfaces = variable.superInterfaces(); for (int j = 0, length = interfaces.length; j < length; j++) { missingTypes = interfaces[j].collectMissingTypes(missingTypes); } } } return missingTypes; }
public TypeBinding erasure() { // lazily initialize field that may be required in super.erasure(): if (this.superclass == null) this.superclass = this.environment.getType(TypeConstants.JAVA_LANG_OBJECT); return super.erasure(); } }
public String debugName() { if (this.wildcard != null) { StringBuffer buffer = new StringBuffer(10); buffer .append(TypeConstants.WILDCARD_CAPTURE_NAME_PREFIX) .append(this.captureID) .append(TypeConstants.WILDCARD_CAPTURE_NAME_SUFFIX) .append(this.wildcard.debugName()); return buffer.toString(); } return super.debugName(); }
public char[] computeUniqueKey(boolean isLeaf) { StringBuffer buffer = new StringBuffer(); Binding declaring = this.declaringElement; if (!isLeaf && declaring.kind() == Binding.METHOD) { // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=97902 MethodBinding methodBinding = (MethodBinding) declaring; ReferenceBinding declaringClass = methodBinding.declaringClass; buffer.append(declaringClass.computeUniqueKey(false/*not a leaf*/)); buffer.append(':'); MethodBinding[] methods = declaringClass.methods(); if (methods != null) for (int i = 0, length = methods.length; i < length; i++) { MethodBinding binding = methods[i]; if (binding == methodBinding) { buffer.append(i); break; } } } else { buffer.append(declaring.computeUniqueKey(false/*not a leaf*/)); buffer.append(':'); } buffer.append(genericTypeSignature()); int length = buffer.length(); char[] uniqueKey = new char[length]; buffer.getChars(0, length, uniqueKey, 0); return uniqueKey; } public char[] constantPoolName() { /* java/lang/Object */
sig.append('<'); for (int i = 0, length = this.typeVariables.length; i < length; i++) sig.append(this.typeVariables[i].genericSignature()); sig.append('>'); } else {
@Override public TypeMirror getUpperBound() { TypeVariableBinding typeVariableBinding = (TypeVariableBinding) this._binding; TypeBinding firstBound = typeVariableBinding.firstBound; ReferenceBinding[] superInterfaces = typeVariableBinding.superInterfaces; if (firstBound == null || superInterfaces.length == 0) { // no explicit bound return _env.getFactory().newTypeMirror(typeVariableBinding.upperBound()); } if (firstBound != null && superInterfaces.length == 1 && superInterfaces[0] == firstBound) { // only one bound that is an interface return _env.getFactory().newTypeMirror(typeVariableBinding.upperBound()); } return this._env.getFactory().newTypeMirror((TypeVariableBinding) this._binding); }
/** * Compute the initial type bounds for one inference variable as per JLS8 sect 18.1.3. */ TypeBound[] getTypeBounds(InferenceVariable variable, InferenceSubstitution theta) { int n = boundsCount(); if (n == 0) return NO_TYPE_BOUNDS; TypeBound[] bounds = new TypeBound[n]; int idx = 0; if (!this.firstBound.isInterface()) bounds[idx++] = TypeBound.createBoundOrDependency(theta, this.firstBound, variable); for (int i = 0; i < this.superInterfaces.length; i++) bounds[idx++] = TypeBound.createBoundOrDependency(theta, this.superInterfaces[i], variable); return bounds; }
/** * Iterate type arguments, and validate them according to corresponding variable bounds. */ public void boundCheck(Scope scope, TypeReference[] argumentReferences) { if ((this.tagBits & TagBits.PassedBoundCheck) == 0) { boolean hasErrors = false; TypeVariableBinding[] typeVariables = this.type.typeVariables(); if (this.arguments != null && typeVariables != null) { // arguments may be null in error cases for (int i = 0, length = typeVariables.length; i < length; i++) { if (typeVariables[i].boundCheck(this, this.arguments[i]) != TypeConstants.OK) { hasErrors = true; if ((this.arguments[i].tagBits & TagBits.HasMissingType) == 0) { // do not report secondary error, if type reference already got complained against scope.problemReporter().typeMismatchError(this.arguments[i], typeVariables[i], this.type, argumentReferences[i]); } } } } if (!hasErrors) this.tagBits |= TagBits.PassedBoundCheck; // no need to recheck it in the future } } /**
for (int i = 0; i < length; i++) { TypeVariableBinding var = this.typeVariables[i]; if (var.boundsCount() <= 1) { arguments[i] = env.convertToRawType(var.upperBound(), false /*do not force conversion of enclosing types*/); } else { TypeBinding[] itsSuperinterfaces = var.superInterfaces(); int superLength = itsSuperinterfaces.length; TypeBinding rawFirstBound = null; TypeBinding[] rawOtherBounds = null; if (var.boundsCount() == superLength) { rawFirstBound = env.convertToRawType(itsSuperinterfaces[0], false); rawOtherBounds = new TypeBinding[superLength - 1]; rawOtherBounds[s - 1] = env.convertToRawType(itsSuperinterfaces[s], false); } else { rawFirstBound = env.convertToRawType(var.superclass(), false); rawOtherBounds = new TypeBinding[superLength]; for (int s = 0; s < superLength; s++)
public List<TypeBinding> collectMissingTypes(List<TypeBinding> missingTypes) { if ((this.tagBits & TagBits.HasMissingType) != 0) { missingTypes = this.returnType.collectMissingTypes(missingTypes); for (int i = 0, max = this.parameters.length; i < max; i++) { missingTypes = this.parameters[i].collectMissingTypes(missingTypes); } for (int i = 0, max = this.thrownExceptions.length; i < max; i++) { missingTypes = this.thrownExceptions[i].collectMissingTypes(missingTypes); } for (int i = 0, max = this.typeVariables.length; i < max; i++) { TypeVariableBinding variable = this.typeVariables[i]; missingTypes = variable.superclass().collectMissingTypes(missingTypes); ReferenceBinding[] interfaces = variable.superInterfaces(); for (int j = 0, length = interfaces.length; j < length; j++) { missingTypes = interfaces[j].collectMissingTypes(missingTypes); } } } return missingTypes; }
@Override public TypeBinding erasure() { // lazily initialize field that may be required in super.erasure(): if (this.superclass == null) this.superclass = this.environment.getType(TypeConstants.JAVA_LANG_OBJECT); return super.erasure(); } }
public String debugName() { if (this.wildcard != null) { StringBuffer buffer = new StringBuffer(10); buffer .append(TypeConstants.WILDCARD_CAPTURE_NAME_PREFIX) .append(this.captureID) .append(TypeConstants.WILDCARD_CAPTURE_NAME_SUFFIX) .append(this.wildcard.debugName()); return buffer.toString(); } return super.debugName(); }
public char[] computeUniqueKey(boolean isLeaf) { StringBuffer buffer = new StringBuffer(); Binding declaring = this.declaringElement; if (!isLeaf && declaring.kind() == Binding.METHOD) { // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=97902 MethodBinding methodBinding = (MethodBinding) declaring; ReferenceBinding declaringClass = methodBinding.declaringClass; buffer.append(declaringClass.computeUniqueKey(false/*not a leaf*/)); buffer.append(':'); MethodBinding[] methods = declaringClass.methods(); if (methods != null) for (int i = 0, length = methods.length; i < length; i++) { MethodBinding binding = methods[i]; if (binding == methodBinding) { buffer.append(i); break; } } } else { buffer.append(declaring.computeUniqueKey(false/*not a leaf*/)); buffer.append(':'); } buffer.append(genericTypeSignature()); int length = buffer.length(); char[] uniqueKey = new char[length]; buffer.getChars(0, length, uniqueKey, 0); return uniqueKey; } public char[] constantPoolName() { /* java/lang/Object */
sig.append('<'); for (int i = 0, length = this.typeVariables.length; i < length; i++) sig.append(this.typeVariables[i].genericSignature()); sig.append('>'); } else {
@Override public TypeMirror getUpperBound() { TypeVariableBinding typeVariableBinding = (TypeVariableBinding) this._binding; TypeBinding firstBound = typeVariableBinding.firstBound; ReferenceBinding[] superInterfaces = typeVariableBinding.superInterfaces; if (firstBound == null || superInterfaces.length == 0) { // no explicit bound return _env.getFactory().newTypeMirror(typeVariableBinding.upperBound()); } if (firstBound != null && superInterfaces.length == 1 && superInterfaces[0] == firstBound) { // only one bound that is an interface return _env.getFactory().newTypeMirror(typeVariableBinding.upperBound()); } return this._env.getFactory().newDeclaredType((TypeVariableBinding) this._binding); }
/** * Compute the initial type bounds for one inference variable as per JLS8 sect 18.1.3. */ TypeBound[] getTypeBounds(InferenceVariable variable, InferenceSubstitution theta) { int n = boundsCount(); if (n == 0) return NO_TYPE_BOUNDS; TypeBound[] bounds = new TypeBound[n]; int idx = 0; if (!this.firstBound.isInterface()) bounds[idx++] = TypeBound.createBoundOrDependency(theta, this.firstBound, variable); for (int i = 0; i < this.superInterfaces.length; i++) bounds[idx++] = TypeBound.createBoundOrDependency(theta, this.superInterfaces[i], variable); return bounds; }