/** * 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) {
/** * 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) {
/** * 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) {
/** * Returns true if the argument type satisfies all bounds of the type parameter * @param location if non-null this may be used for reporting errors relating to null type annotations (if enabled) */ public TypeConstants.BoundCheckStatus boundCheck(Substitution substitution, TypeBinding argumentType, Scope scope, ASTNode location) { TypeConstants.BoundCheckStatus code = internalBoundCheck(substitution, argumentType, scope, location); if (code == BoundCheckStatus.MISMATCH) { if (argumentType instanceof TypeVariableBinding && scope != null) { TypeBinding bound = ((TypeVariableBinding)argumentType).firstBound; if (bound instanceof ParameterizedTypeBinding) { BoundCheckStatus code2 = boundCheck(substitution, bound.capture(scope, -1, -1), scope, location); // no capture position needed as this capture will never escape this context return code.betterOf(code2); } } } return code; } private TypeConstants.BoundCheckStatus internalBoundCheck(Substitution substitution, TypeBinding argumentType, Scope scope, ASTNode location) {
/** * Returns true if the argument type satisfies all bounds of the type parameter * @param location if non-null this may be used for reporting errors relating to null type annotations (if enabled) */ public TypeConstants.BoundCheckStatus boundCheck(Substitution substitution, TypeBinding argumentType, Scope scope, ASTNode location) { TypeConstants.BoundCheckStatus code = internalBoundCheck(substitution, argumentType, scope, location); if (code == BoundCheckStatus.MISMATCH) { if (argumentType instanceof TypeVariableBinding && scope != null) { TypeBinding bound = ((TypeVariableBinding)argumentType).firstBound; if (bound instanceof ParameterizedTypeBinding) { BoundCheckStatus code2 = boundCheck(substitution, bound.capture(scope, -1, -1), scope, location); // no capture position needed as this capture will never escape this context return code.betterOf(code2); } } } return code; } private TypeConstants.BoundCheckStatus internalBoundCheck(Substitution substitution, TypeBinding argumentType, Scope scope, ASTNode location) {
/** * Returns true if the argument type satisfies all bounds of the type parameter * @param location if non-null this may be used for reporting errors relating to null type annotations (if enabled) */ public TypeConstants.BoundCheckStatus boundCheck(Substitution substitution, TypeBinding argumentType, Scope scope, ASTNode location) { TypeConstants.BoundCheckStatus code = internalBoundCheck(substitution, argumentType, scope, location); if (code == BoundCheckStatus.MISMATCH) { if (argumentType instanceof TypeVariableBinding && scope != null) { TypeBinding bound = ((TypeVariableBinding)argumentType).firstBound; if (bound instanceof ParameterizedTypeBinding) { BoundCheckStatus code2 = boundCheck(substitution, bound.capture(scope, -1, -1), scope, location); // no capture position needed as this capture will never escape this context return code.betterOf(code2); } } } return code; } private TypeConstants.BoundCheckStatus internalBoundCheck(Substitution substitution, TypeBinding argumentType, Scope scope, ASTNode location) {
/** * Returns true if the argument type satisfies all bounds of the type parameter * @param location if non-null this may be used for reporting errors relating to null type annotations (if enabled) */ public TypeConstants.BoundCheckStatus boundCheck(Substitution substitution, TypeBinding argumentType, Scope scope, ASTNode location) { TypeConstants.BoundCheckStatus code = internalBoundCheck(substitution, argumentType, scope, location); if (code == BoundCheckStatus.MISMATCH) { if (argumentType instanceof TypeVariableBinding && scope != null) { TypeBinding bound = ((TypeVariableBinding)argumentType).firstBound; if (bound instanceof ParameterizedTypeBinding) { BoundCheckStatus code2 = boundCheck(substitution, bound.capture(scope, -1, -1), scope, location); // no capture position needed as this capture will never escape this context return code.betterOf(code2); } } } return code; } private TypeConstants.BoundCheckStatus internalBoundCheck(Substitution substitution, TypeBinding argumentType, Scope scope, ASTNode location) {
/** * Returns true if the argument type satisfies all bounds of the type parameter * @param location if non-null this may be used for reporting errors relating to null type annotations (if enabled) */ public TypeConstants.BoundCheckStatus boundCheck(Substitution substitution, TypeBinding argumentType, Scope scope, ASTNode location) { TypeConstants.BoundCheckStatus code = internalBoundCheck(substitution, argumentType, scope, location); if (code == BoundCheckStatus.MISMATCH) { if (argumentType instanceof TypeVariableBinding && scope != null) { TypeBinding bound = ((TypeVariableBinding)argumentType).firstBound; if (bound instanceof ParameterizedTypeBinding) { BoundCheckStatus code2 = boundCheck(substitution, bound.capture(scope, -1, -1), scope, location); // no capture position needed as this capture will never escape this context return code.betterOf(code2); } } } return code; } private TypeConstants.BoundCheckStatus internalBoundCheck(Substitution substitution, TypeBinding argumentType, Scope scope, ASTNode location) {
/** * 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], scope) != 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 } } /**
/** * 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 } } /**
/** * 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 } } /**
/** * 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 } } /**
/** * 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], scope) != 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 } } /**
/** * 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 // per JLS 4.5 we should capture 'this' for (int i = 0, length = typeVariables.length; i < length; i++) { BoundCheckStatus checkStatus = typeVariables[i].boundCheck(this, this.arguments[i], scope, argumentReferences[i]); hasErrors |= checkStatus != BoundCheckStatus.OK; if (!checkStatus.isOKbyJLS() && (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 } } /**
/** * 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++) { BoundCheckStatus checkStatus = typeVariables[i].boundCheck(this, this.arguments[i], scope, argumentReferences[i]); hasErrors |= checkStatus != BoundCheckStatus.OK; if (!checkStatus.isOKbyJLS() && (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 } } /**
/** * 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 // per JLS 4.5 we should capture 'this' for (int i = 0, length = typeVariables.length; i < length; i++) { BoundCheckStatus checkStatus = typeVariables[i].boundCheck(this, this.arguments[i], scope, argumentReferences[i]); hasErrors |= checkStatus != BoundCheckStatus.OK; if (!checkStatus.isOKbyJLS() && (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 } } /**
/** * 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++) { BoundCheckStatus checkStatus = typeVariables[i].boundCheck(this, this.arguments[i], scope, argumentReferences[i]); hasErrors |= checkStatus != BoundCheckStatus.OK; if (!checkStatus.isOKbyJLS() && (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 } } /**
@Override protected MethodBinding[] getInterfaceAbstractContracts(Scope scope, boolean replaceWildcards) throws InvalidInputException { if (replaceWildcards) { TypeBinding[] types = getNonWildcardParameterization(scope); if (types == null) return new MethodBinding[] { new ProblemMethodBinding(TypeConstants.ANONYMOUS_METHOD, null, ProblemReasons.NotAWellFormedParameterizedType) }; for (int i = 0; i < types.length; i++) { if (TypeBinding.notEquals(types[i], this.arguments[i])) { // non-wildcard parameterization differs from this, so use it: ParameterizedTypeBinding declaringType = scope.environment().createParameterizedType(this.type, types, this.type.enclosingType()); TypeVariableBinding [] typeParameters = this.type.typeVariables(); for (int j = 0, length = typeParameters.length; j < length; j++) { if (!typeParameters[j].boundCheck(declaringType, types[j], scope, null).isOKbyJLS()) return new MethodBinding[] { new ProblemMethodBinding(TypeConstants.ANONYMOUS_METHOD, null, ProblemReasons.NotAWellFormedParameterizedType) }; } return declaringType.getInterfaceAbstractContracts(scope, replaceWildcards); } } } return super.getInterfaceAbstractContracts(scope, replaceWildcards); } public MethodBinding getSingleAbstractMethod(final Scope scope, boolean replaceWildcards) {
@Override protected MethodBinding[] getInterfaceAbstractContracts(Scope scope, boolean replaceWildcards) throws InvalidInputException { if (replaceWildcards) { TypeBinding[] types = getNonWildcardParameterization(scope); if (types == null) return new MethodBinding[] { new ProblemMethodBinding(TypeConstants.ANONYMOUS_METHOD, null, ProblemReasons.NotAWellFormedParameterizedType) }; for (int i = 0; i < types.length; i++) { if (TypeBinding.notEquals(types[i], this.arguments[i])) { // non-wildcard parameterization differs from this, so use it: ParameterizedTypeBinding declaringType = scope.environment().createParameterizedType(this.type, types, this.type.enclosingType()); TypeVariableBinding [] typeParameters = this.type.typeVariables(); for (int j = 0, length = typeParameters.length; j < length; j++) { if (!typeParameters[j].boundCheck(declaringType, types[j], scope, null).isOKbyJLS()) return new MethodBinding[] { new ProblemMethodBinding(TypeConstants.ANONYMOUS_METHOD, null, ProblemReasons.NotAWellFormedParameterizedType) }; } return declaringType.getInterfaceAbstractContracts(scope, replaceWildcards); } } } return super.getInterfaceAbstractContracts(scope, replaceWildcards); } public MethodBinding getSingleAbstractMethod(final Scope scope, boolean replaceWildcards) {
@Override protected MethodBinding[] getInterfaceAbstractContracts(Scope scope, boolean replaceWildcards, boolean filterDefaultMethods) throws InvalidInputException { if (replaceWildcards) { TypeBinding[] types = getNonWildcardParameterization(scope); if (types == null) return new MethodBinding[] { new ProblemMethodBinding(TypeConstants.ANONYMOUS_METHOD, null, ProblemReasons.NotAWellFormedParameterizedType) }; for (int i = 0; i < types.length; i++) { if (TypeBinding.notEquals(types[i], this.arguments[i])) { // non-wildcard parameterization differs from this, so use it: ParameterizedTypeBinding declaringType = scope.environment().createParameterizedType(this.type, types, this.type.enclosingType()); TypeVariableBinding [] typeParameters = this.type.typeVariables(); for (int j = 0, length = typeParameters.length; j < length; j++) { if (!typeParameters[j].boundCheck(declaringType, types[j], scope, null).isOKbyJLS()) return new MethodBinding[] { new ProblemMethodBinding(TypeConstants.ANONYMOUS_METHOD, null, ProblemReasons.NotAWellFormedParameterizedType) }; } return declaringType.getInterfaceAbstractContracts(scope, replaceWildcards, filterDefaultMethods); } } } return super.getInterfaceAbstractContracts(scope, replaceWildcards, filterDefaultMethods); } @Override