package org.eclipse.jdt.internal.compiler.lookup;
import java.util.List;
import java.util.Set;
import org.eclipse.jdt.core.compiler.CharOperation;
import org.eclipse.jdt.internal.compiler.ast.Annotation;
import org.eclipse.jdt.internal.compiler.ast.Wildcard;
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
public class WildcardBinding extends ReferenceBinding {
public ReferenceBinding genericType;
public int rank;
public TypeBinding bound;
public TypeBinding[] otherBounds;
char[] genericSignature;
public int boundKind;
ReferenceBinding superclass;
ReferenceBinding[] superInterfaces;
TypeVariableBinding typeVariable;
LookupEnvironment environment;
public WildcardBinding(ReferenceBinding genericType, int rank, TypeBinding bound, TypeBinding[] otherBounds, int boundKind, LookupEnvironment environment) {
this.rank = rank;
this.boundKind = boundKind;
this.modifiers = ClassFileConstants.AccPublic | ExtraCompilerModifiers.AccGenericSignature;
this.environment = environment;
initialize(genericType, bound, otherBounds);
if (genericType instanceof UnresolvedReferenceBinding)
((UnresolvedReferenceBinding) genericType).addWrapper(this, environment);
if (bound instanceof UnresolvedReferenceBinding)
((UnresolvedReferenceBinding) bound).addWrapper(this, environment);
this.tagBits |= TagBits.HasUnresolvedTypeVariables;
this.typeBits = TypeIds.BitUninitialized;
}
@Override
TypeBinding bound() {
return this.bound;
}
@Override
int boundKind() {
return this.boundKind;
}
public TypeBinding allBounds() {
if (this.otherBounds == null || this.otherBounds.length == 0)
return this.bound;
ReferenceBinding[] allBounds = new ReferenceBinding[this.otherBounds.length+1];
try {
allBounds[0] = (ReferenceBinding) this.bound;
System.arraycopy(this.otherBounds, 0, allBounds, 1, this.otherBounds.length);
} catch (ClassCastException | ArrayStoreException ase) {
return this.bound;
}
return this.environment.createIntersectionType18(allBounds);
}
@Override
public void setTypeAnnotations(AnnotationBinding[] annotations, boolean evalNullAnnotations) {
this.tagBits |= TagBits.HasTypeAnnotations;
if (annotations != null && annotations.length != 0) {
this.typeAnnotations = annotations;
}
if (evalNullAnnotations) {
evaluateNullAnnotations(null, null);
}
}
public void evaluateNullAnnotations(Scope scope, Wildcard wildcard) {
long nullTagBits = determineNullBitsFromDeclaration(scope, wildcard);
if (nullTagBits == 0L) {
TypeVariableBinding typeVariable2 = typeVariable();
if (typeVariable2 != null) {
long typeVariableNullTagBits = typeVariable2.tagBits & TagBits.AnnotationNullMASK;
if (typeVariableNullTagBits != 0L) {
nullTagBits = typeVariableNullTagBits;
}
}
}
if (nullTagBits != 0)
this.tagBits = (this.tagBits & ~TagBits.AnnotationNullMASK) | nullTagBits | TagBits.HasNullTypeAnnotation;
}
public long determineNullBitsFromDeclaration(Scope scope, Wildcard wildcard) {
long nullTagBits = 0L;
AnnotationBinding [] annotations = this.typeAnnotations;
if (annotations != null) {
for (int i = 0, length = annotations.length; i < length; i++) {
AnnotationBinding annotation = annotations[i];
if (annotation != null) {
if (annotation.type.hasNullBit(TypeIds.BitNullableAnnotation)) {
if ((nullTagBits & TagBits.AnnotationNonNull) == 0) {
nullTagBits |= TagBits.AnnotationNullable;
} else {
if (wildcard != null) {
Annotation annotation1 = wildcard.findAnnotation(TagBits.AnnotationNullable);
if (annotation1 != null)
scope.problemReporter().contradictoryNullAnnotations(annotation1);
}
}
} else if (annotation.type.hasNullBit(TypeIds.BitNonNullAnnotation)) {
if ((nullTagBits & TagBits.AnnotationNullable) == 0) {
nullTagBits |= TagBits.AnnotationNonNull;
} else {
if (wildcard != null) {
Annotation annotation1 = wildcard.findAnnotation(TagBits.AnnotationNonNull);
if (annotation1 != null)
scope.problemReporter().contradictoryNullAnnotations(annotation1);
}
}
}
}
}
}
if (this.bound != null && this.bound.isValidBinding()) {
long boundNullTagBits = this.bound.tagBits & TagBits.AnnotationNullMASK;
if (boundNullTagBits != 0L) {
if (this.boundKind == Wildcard.SUPER) {
if ((boundNullTagBits & TagBits.AnnotationNullable) != 0) {
if (nullTagBits == 0L) {
nullTagBits = TagBits.AnnotationNullable;
} else if (wildcard != null && (nullTagBits & TagBits.AnnotationNonNull) != 0) {
Annotation annotation = wildcard.bound.findAnnotation(boundNullTagBits);
if (annotation == null) {
TypeBinding newBound = this.bound.withoutToplevelNullAnnotation();
this.bound = newBound;
wildcard.bound.resolvedType = newBound;
} else {
scope.problemReporter().contradictoryNullAnnotationsOnBounds(annotation, nullTagBits);
}
}
}
} else {
if ((boundNullTagBits & TagBits.AnnotationNonNull) != 0) {
if (nullTagBits == 0L) {
nullTagBits = TagBits.AnnotationNonNull;
} else if (wildcard != null && (nullTagBits & TagBits.AnnotationNullable) != 0) {
Annotation annotation = wildcard.bound.findAnnotation(boundNullTagBits);
if (annotation == null) {
TypeBinding newBound = this.bound.withoutToplevelNullAnnotation();
this.bound = newBound;
wildcard.bound.resolvedType = newBound;
} else {
scope.problemReporter().contradictoryNullAnnotationsOnBounds(annotation, nullTagBits);
}
}
}
if (nullTagBits == 0L && this.otherBounds != null) {
for (int i = 0, length = this.otherBounds.length; i < length; i++) {
if ((this.otherBounds[i].tagBits & TagBits.AnnotationNonNull) != 0) {
nullTagBits = TagBits.AnnotationNonNull;
break;
}
}
}
}
}
}
return nullTagBits;
}
@Override
public ReferenceBinding actualType() {
return this.genericType;
}
@Override
TypeBinding[] additionalBounds() {
return this.otherBounds;
}
@Override
public int kind() {
return this.otherBounds == null ? Binding.WILDCARD_TYPE : Binding.INTERSECTION_TYPE;
}
public boolean boundCheck(TypeBinding argumentType) {
switch (this.boundKind) {
case Wildcard.UNBOUND :
return true;
case Wildcard.EXTENDS :
if (!argumentType.isCompatibleWith(this.bound)) return false;
for (int i = 0, length = this.otherBounds == null ? 0 : this.otherBounds.length; i < length; i++) {
if (!argumentType.isCompatibleWith(this.otherBounds[i])) return false;
}
return true;
default:
return argumentType.isCompatibleWith(this.bound);
}
}
@Override
public boolean canBeInstantiated() {
return false;
}
@Override
public List<TypeBinding> collectMissingTypes(List<TypeBinding> missingTypes) {
if ((this.tagBits & TagBits.HasMissingType) != 0) {
missingTypes = this.bound.collectMissingTypes(missingTypes);
}
return missingTypes;
}
@Override
public void collectSubstitutes(Scope scope, TypeBinding actualType, InferenceContext inferenceContext, int constraint) {
if ((this.tagBits & TagBits.HasTypeVariable) == 0) return;
if (actualType == TypeBinding.NULL || actualType.kind() == POLY_TYPE) return;
if (actualType.isCapture()) {
CaptureBinding capture = (CaptureBinding) actualType;
actualType = capture.wildcard;
}
switch (constraint) {
case TypeConstants.CONSTRAINT_EXTENDS :
switch (this.boundKind) {
case Wildcard.UNBOUND:
break;
case Wildcard.EXTENDS:
switch(actualType.kind()) {
case Binding.WILDCARD_TYPE :
WildcardBinding actualWildcard = (WildcardBinding) actualType;
switch(actualWildcard.boundKind) {
case Wildcard.UNBOUND:
break;
case Wildcard.EXTENDS:
this.bound.collectSubstitutes(scope, actualWildcard.bound, inferenceContext, TypeConstants.CONSTRAINT_EXTENDS);
break;
case Wildcard.SUPER:
break;
}
break;
case Binding.INTERSECTION_TYPE :
WildcardBinding actualIntersection = (WildcardBinding) actualType;
this.bound.collectSubstitutes(scope, actualIntersection.bound, inferenceContext, TypeConstants.CONSTRAINT_EXTENDS);
for (int i = 0, length = actualIntersection.otherBounds.length; i < length; i++) {
this.bound.collectSubstitutes(scope, actualIntersection.otherBounds[i], inferenceContext, TypeConstants.CONSTRAINT_EXTENDS);
}
break;
default :
this.bound.collectSubstitutes(scope, actualType, inferenceContext, TypeConstants.CONSTRAINT_EXTENDS);
break;
}
break;
case Wildcard.SUPER:
switch (actualType.kind()) {
case Binding.WILDCARD_TYPE :
WildcardBinding actualWildcard = (WildcardBinding) actualType;
switch(actualWildcard.boundKind) {
case Wildcard.UNBOUND:
break;
case Wildcard.EXTENDS:
break;
case Wildcard.SUPER:
this.bound.collectSubstitutes(scope, actualWildcard.bound, inferenceContext, TypeConstants.CONSTRAINT_SUPER);
for (int i = 0, length = actualWildcard.otherBounds == null ? 0 : actualWildcard.otherBounds.length; i < length; i++) {
this.bound.collectSubstitutes(scope, actualWildcard.otherBounds[i], inferenceContext, TypeConstants.CONSTRAINT_SUPER);
}
break;
}
break;
case Binding.INTERSECTION_TYPE :
break;
default :
this.bound.collectSubstitutes(scope, actualType, inferenceContext, TypeConstants.CONSTRAINT_SUPER);
break;
}
break;
}
break;
case TypeConstants.CONSTRAINT_EQUAL :
switch (this.boundKind) {
case Wildcard.UNBOUND:
break;
case Wildcard.EXTENDS:
switch (actualType.kind()) {
case Binding.WILDCARD_TYPE :
WildcardBinding actualWildcard = (WildcardBinding) actualType;
switch(actualWildcard.boundKind) {
case Wildcard.UNBOUND:
break;
case Wildcard.EXTENDS:
this.bound.collectSubstitutes(scope, actualWildcard.bound, inferenceContext, TypeConstants.CONSTRAINT_EQUAL);
for (int i = 0, length = actualWildcard.otherBounds == null ? 0 : actualWildcard.otherBounds.length; i < length; i++) {
this.bound.collectSubstitutes(scope, actualWildcard.otherBounds[i], inferenceContext, TypeConstants.CONSTRAINT_EQUAL);
}
break;
case Wildcard.SUPER:
break;
}
break;
case Binding.INTERSECTION_TYPE :
WildcardBinding actuaIntersection = (WildcardBinding) actualType;
this.bound.collectSubstitutes(scope, actuaIntersection.bound, inferenceContext, TypeConstants.CONSTRAINT_EQUAL);
for (int i = 0, length = actuaIntersection.otherBounds == null ? 0 : actuaIntersection.otherBounds.length; i < length; i++) {
this.bound.collectSubstitutes(scope, actuaIntersection.otherBounds[i], inferenceContext, TypeConstants.CONSTRAINT_EQUAL);
}
break;
default :
break;
}
break;
case Wildcard.SUPER:
switch (actualType.kind()) {
case Binding.WILDCARD_TYPE :
WildcardBinding actualWildcard = (WildcardBinding) actualType;
switch(actualWildcard.boundKind) {
case Wildcard.UNBOUND:
break;
case Wildcard.EXTENDS:
break;
case Wildcard.SUPER:
this.bound.collectSubstitutes(scope, actualWildcard.bound, inferenceContext, TypeConstants.CONSTRAINT_EQUAL);
for (int i = 0, length = actualWildcard.otherBounds == null ? 0 : actualWildcard.otherBounds.length; i < length; i++) {
this.bound.collectSubstitutes(scope, actualWildcard.otherBounds[i], inferenceContext, TypeConstants.CONSTRAINT_EQUAL);
}
break;
}
break;
case Binding.INTERSECTION_TYPE :
break;
default :
break;
}
break;
}
break;
case TypeConstants.CONSTRAINT_SUPER :
switch (this.boundKind) {
case Wildcard.UNBOUND:
break;
case Wildcard.EXTENDS:
switch (actualType.kind()) {
case Binding.WILDCARD_TYPE :
WildcardBinding actualWildcard = (WildcardBinding) actualType;
switch(actualWildcard.boundKind) {
case Wildcard.UNBOUND:
break;
case Wildcard.EXTENDS:
this.bound.collectSubstitutes(scope, actualWildcard.bound, inferenceContext, TypeConstants.CONSTRAINT_SUPER);
for (int i = 0, length = actualWildcard.otherBounds == null ? 0 : actualWildcard.otherBounds.length; i < length; i++) {
this.bound.collectSubstitutes(scope, actualWildcard.otherBounds[i], inferenceContext, TypeConstants.CONSTRAINT_SUPER);
}
break;
case Wildcard.SUPER:
break;
}
break;
case Binding.INTERSECTION_TYPE :
WildcardBinding actualIntersection = (WildcardBinding) actualType;
this.bound.collectSubstitutes(scope, actualIntersection.bound, inferenceContext, TypeConstants.CONSTRAINT_SUPER);
for (int i = 0, length = actualIntersection.otherBounds == null ? 0 : actualIntersection.otherBounds.length; i < length; i++) {
this.bound.collectSubstitutes(scope, actualIntersection.otherBounds[i], inferenceContext, TypeConstants.CONSTRAINT_SUPER);
}
break;
default :
break;
}
break;
case Wildcard.SUPER:
switch (actualType.kind()) {
case Binding.WILDCARD_TYPE :
WildcardBinding actualWildcard = (WildcardBinding) actualType;
switch(actualWildcard.boundKind) {
case Wildcard.UNBOUND:
break;
case Wildcard.EXTENDS:
break;
case Wildcard.SUPER:
this.bound.collectSubstitutes(scope, actualWildcard.bound, inferenceContext, TypeConstants.CONSTRAINT_SUPER);
for (int i = 0, length = actualWildcard.otherBounds == null ? 0 : actualWildcard.otherBounds.length; i < length; i++) {
this.bound.collectSubstitutes(scope, actualWildcard.otherBounds[i], inferenceContext, TypeConstants.CONSTRAINT_SUPER);
}
break;
}
break;
case Binding.INTERSECTION_TYPE :
break;
default :
break;
}
break;
}
break;
}
}
@Override
public char[] computeUniqueKey(boolean isLeaf) {
char[] genericTypeKey = this.genericType.computeUniqueKey(false);
char[] wildCardKey;
char[] rankComponent = ('{' + String.valueOf(this.rank) + '}').toCharArray();
switch (this.boundKind) {
case Wildcard.UNBOUND :
wildCardKey = TypeConstants.WILDCARD_STAR;
break;
case Wildcard.EXTENDS :
wildCardKey = CharOperation.concat(TypeConstants.WILDCARD_PLUS, this.bound.computeUniqueKey(false));
break;
default:
wildCardKey = CharOperation.concat(TypeConstants.WILDCARD_MINUS, this.bound.computeUniqueKey(false));
break;
}
return CharOperation.concat(genericTypeKey, rankComponent, wildCardKey);
}
@Override
public char[] constantPoolName() {
return erasure().constantPoolName();
}
@Override
public TypeBinding clone(TypeBinding immaterial) {
return new WildcardBinding(this.genericType, this.rank, this.bound, this.otherBounds, this.boundKind, this.environment);
}
@Override
public String annotatedDebugName() {
StringBuffer buffer = new StringBuffer(16);
AnnotationBinding [] annotations = getTypeAnnotations();
for (int i = 0, length = annotations == null ? 0 : annotations.length; i < length; i++) {
buffer.append(annotations[i]);
buffer.append(' ');
}
switch (this.boundKind) {
case Wildcard.UNBOUND :
return buffer.append(TypeConstants.WILDCARD_NAME).toString();
case Wildcard.EXTENDS :
if (this.otherBounds == null)
return buffer.append(CharOperation.concat(TypeConstants.WILDCARD_NAME, TypeConstants.WILDCARD_EXTENDS, this.bound.annotatedDebugName().toCharArray())).toString();
buffer.append(this.bound.annotatedDebugName());
for (int i = 0, length = this.otherBounds.length; i < length; i++) {
buffer.append(" & ").append(this.otherBounds[i].annotatedDebugName());
}
return buffer.toString();
default:
return buffer.append(CharOperation.concat(TypeConstants.WILDCARD_NAME, TypeConstants.WILDCARD_SUPER, this.bound.annotatedDebugName().toCharArray())).toString();
}
}
@Override
public String debugName() {
return toString();
}
@Override
public TypeBinding erasure() {
if (this.otherBounds == null) {
if (this.boundKind == Wildcard.EXTENDS)
return this.bound.erasure();
TypeVariableBinding var = typeVariable();
if (var != null)
return var.erasure();
return this.genericType;
}
return this.bound.id == TypeIds.T_JavaLangObject
? this.otherBounds[0].erasure()
: this.bound.erasure();
}
@Override
public char[] genericTypeSignature() {
if (this.genericSignature == null) {
switch (this.boundKind) {
case Wildcard.UNBOUND :
this.genericSignature = TypeConstants.WILDCARD_STAR;
break;
case Wildcard.EXTENDS :
this.genericSignature = CharOperation.concat(TypeConstants.WILDCARD_PLUS, this.bound.genericTypeSignature());
break;
default:
this.genericSignature = CharOperation.concat(TypeConstants.WILDCARD_MINUS, this.bound.genericTypeSignature());
}
}
return this.genericSignature;
}
@Override
public int hashCode() {
return this.genericType.hashCode();
}
@Override
public boolean hasTypeBit(int bit) {
if (this.typeBits == TypeIds.BitUninitialized) {
this.typeBits = 0;
if (this.superclass != null && this.superclass.hasTypeBit(~TypeIds.BitUninitialized))
this.typeBits |= (this.superclass.typeBits & TypeIds.InheritableBits);
if (this.superInterfaces != null)
for (int i = 0, l = this.superInterfaces.length; i < l; i++)
if (this.superInterfaces[i].hasTypeBit(~TypeIds.BitUninitialized))
this.typeBits |= (this.superInterfaces[i].typeBits & TypeIds.InheritableBits);
}
return (this.typeBits & bit) != 0;
}
void initialize(ReferenceBinding someGenericType, TypeBinding someBound, TypeBinding[] someOtherBounds) {
this.genericType = someGenericType;
this.bound = someBound;
this.otherBounds = someOtherBounds;
if (someGenericType != null) {
this.fPackage = someGenericType.getPackage();
}
if (someBound != null) {
this.tagBits |= someBound.tagBits & (TagBits.HasTypeVariable | TagBits.HasMissingType | TagBits.ContainsNestedTypeReferences |
TagBits.HasNullTypeAnnotation | TagBits.HasCapturedWildcard);
}
if (someOtherBounds != null) {
for (int i = 0, max = someOtherBounds.length; i < max; i++) {
TypeBinding someOtherBound = someOtherBounds[i];
this.tagBits |= someOtherBound.tagBits & (TagBits.ContainsNestedTypeReferences | TagBits.HasNullTypeAnnotation | TagBits.HasCapturedWildcard);
}
}
}
@Override
public boolean isSuperclassOf(ReferenceBinding otherType) {
if (this.boundKind == Wildcard.SUPER) {
if (this.bound instanceof ReferenceBinding) {
return ((ReferenceBinding) this.bound).isSuperclassOf(otherType);
} else {
return otherType.id == TypeIds.T_JavaLangObject;
}
}
return false;
}
@Override
public boolean isIntersectionType() {
return this.otherBounds != null;
}
@Override
public ReferenceBinding[] getIntersectingTypes() {
if (isIntersectionType()) {
ReferenceBinding[] allBounds = new ReferenceBinding[this.otherBounds.length+1];
try {
allBounds[0] = (ReferenceBinding) this.bound;
System.arraycopy(this.otherBounds, 0, allBounds, 1, this.otherBounds.length);
} catch (ClassCastException | ArrayStoreException ase) {
return null;
}
return allBounds;
}
return null;
}
@Override
public boolean isHierarchyConnected() {
return this.superclass != null && this.superInterfaces != null;
}
boolean inRecursiveFunction = false;
@Override
public boolean enterRecursiveFunction() {
if (this.inRecursiveFunction)
return false;
this.inRecursiveFunction = true;
return true;
}
@Override
public void exitRecursiveFunction() {
this.inRecursiveFunction = false;
}
@Override
public boolean isProperType(boolean admitCapture18) {
if (this.inRecursiveFunction)
return true;
this.inRecursiveFunction = true;
try {
if (this.bound != null && !this.bound.isProperType(admitCapture18))
return false;
if (this.superclass != null && !this.superclass.isProperType(admitCapture18))
return false;
if (this.superInterfaces != null)
for (int i = 0, l = this.superInterfaces.length; i < l; i++)
if (!this.superInterfaces[i].isProperType(admitCapture18))
return false;
return true;
} finally {
this.inRecursiveFunction = false;
}
}
@Override
TypeBinding substituteInferenceVariable(InferenceVariable var, TypeBinding substituteType) {
boolean haveSubstitution = false;
TypeBinding currentBound = this.bound;
if (currentBound != null) {
currentBound = currentBound.substituteInferenceVariable(var, substituteType);
haveSubstitution |= TypeBinding.notEquals(currentBound, this.bound);
}
TypeBinding[] currentOtherBounds = null;
if (this.otherBounds != null) {
int length = this.otherBounds.length;
if (haveSubstitution)
System.arraycopy(this.otherBounds, 0, currentOtherBounds=new ReferenceBinding[length], 0, length);
for (int i = 0; i < length; i++) {
TypeBinding currentOtherBound = this.otherBounds[i];
if (currentOtherBound != null) {
currentOtherBound = currentOtherBound.substituteInferenceVariable(var, substituteType);
if (TypeBinding.notEquals(currentOtherBound, this.otherBounds[i])) {
if (currentOtherBounds == null)
System.arraycopy(this.otherBounds, 0, currentOtherBounds=new ReferenceBinding[length], 0, length);
currentOtherBounds[i] = currentOtherBound;
}
}
}
}
haveSubstitution |= currentOtherBounds != null;
if (haveSubstitution) {
return this.environment.createWildcard(this.genericType, this.rank, currentBound, currentOtherBounds, this.boundKind);
}
return this;
}
@Override
public boolean isUnboundWildcard() {
return this.boundKind == Wildcard.UNBOUND;
}
@Override
public boolean isWildcard() {
return true;
}
@Override
int rank() {
return this.rank;
}
@Override
public char[] readableName() {
switch (this.boundKind) {
case Wildcard.UNBOUND :
return TypeConstants.WILDCARD_NAME;
case Wildcard.EXTENDS :
if (this.otherBounds == null)
return CharOperation.concat(TypeConstants.WILDCARD_NAME, TypeConstants.WILDCARD_EXTENDS, this.bound.readableName());
StringBuffer buffer = new StringBuffer(10);
buffer.append(this.bound.readableName());
for (int i = 0, length = this.otherBounds.length; i < length; i++) {
buffer.append('&').append(this.otherBounds[i].readableName());
}
int length;
char[] result = new char[length = buffer.length()];
buffer.getChars(0, length, result, 0);
return result;
default:
return CharOperation.concat(TypeConstants.WILDCARD_NAME, TypeConstants.WILDCARD_SUPER, this.bound.readableName());
}
}
@Override
public char[] nullAnnotatedReadableName(CompilerOptions options, boolean shortNames) {
StringBuffer buffer = new StringBuffer(10);
appendNullAnnotation(buffer, options);
switch (this.boundKind) {
case Wildcard.UNBOUND :
buffer.append(TypeConstants.WILDCARD_NAME);
break;
case Wildcard.EXTENDS :
if (this.otherBounds == null) {
buffer.append(TypeConstants.WILDCARD_NAME).append(TypeConstants.WILDCARD_EXTENDS);
buffer.append(this.bound.nullAnnotatedReadableName(options, shortNames));
} else {
buffer.append(this.bound.nullAnnotatedReadableName(options, shortNames));
for (int i = 0, length = this.otherBounds.length; i < length; i++) {
buffer.append('&').append(this.otherBounds[i].nullAnnotatedReadableName(options, shortNames));
}
}
break;
default:
buffer.append(TypeConstants.WILDCARD_NAME).append(TypeConstants.WILDCARD_SUPER).append(this.bound.nullAnnotatedReadableName(options, shortNames));
}
int length;
char[] result = new char[length = buffer.length()];
buffer.getChars(0, length, result, 0);
return result;
}
ReferenceBinding resolve() {
if ((this.tagBits & TagBits.HasUnresolvedTypeVariables) == 0)
return this;
this.tagBits &= ~TagBits.HasUnresolvedTypeVariables;
BinaryTypeBinding.resolveType(this.genericType, this.environment, false );
switch(this.boundKind) {
case Wildcard.EXTENDS :
TypeBinding resolveType = BinaryTypeBinding.resolveType(this.bound, this.environment, true );
this.bound = resolveType;
this.tagBits |= resolveType.tagBits & TagBits.ContainsNestedTypeReferences | TagBits.HasCapturedWildcard;
for (int i = 0, length = this.otherBounds == null ? 0 : this.otherBounds.length; i < length; i++) {
resolveType = BinaryTypeBinding.resolveType(this.otherBounds[i], this.environment, true );
this.otherBounds[i]= resolveType;
this.tagBits |= resolveType.tagBits & TagBits.ContainsNestedTypeReferences | TagBits.HasCapturedWildcard;
}
break;
case Wildcard.SUPER :
resolveType = BinaryTypeBinding.resolveType(this.bound, this.environment, true );
this.bound = resolveType;
this.tagBits |= resolveType.tagBits & TagBits.ContainsNestedTypeReferences | TagBits.HasCapturedWildcard;
break;
case Wildcard.UNBOUND :
}
if (this.environment.usesNullTypeAnnotations()) {
evaluateNullAnnotations(null, null);
}
return this;
}
@Override
public char[] shortReadableName() {
switch (this.boundKind) {
case Wildcard.UNBOUND :
return TypeConstants.WILDCARD_NAME;
case Wildcard.EXTENDS :
if (this.otherBounds == null)
return CharOperation.concat(TypeConstants.WILDCARD_NAME, TypeConstants.WILDCARD_EXTENDS, this.bound.shortReadableName());
StringBuffer buffer = new StringBuffer(10);
buffer.append(this.bound.shortReadableName());
for (int i = 0, length = this.otherBounds.length; i < length; i++) {
buffer.append('&').append(this.otherBounds[i].shortReadableName());
}
int length;
char[] result = new char[length = buffer.length()];
buffer.getChars(0, length, result, 0);
return result;
default:
return CharOperation.concat(TypeConstants.WILDCARD_NAME, TypeConstants.WILDCARD_SUPER, this.bound.shortReadableName());
}
}
@Override
public char[] signature() {
if (this.signature == null) {
switch (this.boundKind) {
case Wildcard.EXTENDS :
return this.bound.signature();
default:
return typeVariable().signature();
}
}
return this.signature;
}
@Override
public char[] sourceName() {
switch (this.boundKind) {
case Wildcard.UNBOUND :
return TypeConstants.WILDCARD_NAME;
case Wildcard.EXTENDS :
return CharOperation.concat(TypeConstants.WILDCARD_NAME, TypeConstants.WILDCARD_EXTENDS, this.bound.sourceName());
default:
return CharOperation.concat(TypeConstants.WILDCARD_NAME, TypeConstants.WILDCARD_SUPER, this.bound.sourceName());
}
}
@Override
public ReferenceBinding superclass() {
if (this.superclass == null) {
TypeBinding superType = null;
if (this.boundKind == Wildcard.EXTENDS && !this.bound.isInterface()) {
superType = this.bound;
} else {
TypeVariableBinding variable = typeVariable();
if (variable != null) superType = variable.firstBound;
}
this.superclass = superType instanceof ReferenceBinding && !superType.isInterface()
? (ReferenceBinding) superType
: this.environment.getResolvedJavaBaseType(TypeConstants.JAVA_LANG_OBJECT, null);
}
return this.superclass;
}
@Override
public ReferenceBinding[] superInterfaces() {
if (this.superInterfaces == null) {
if (typeVariable() != null) {
this.superInterfaces = this.typeVariable.superInterfaces();
} else {
this.superInterfaces = Binding.NO_SUPERINTERFACES;
}
if (this.boundKind == Wildcard.EXTENDS) {
if (this.bound.isInterface()) {
int length = this.superInterfaces.length;
System.arraycopy(this.superInterfaces, 0, this.superInterfaces = new ReferenceBinding[length+1], 1, length);
this.superInterfaces[0] = (ReferenceBinding) this.bound;
}
if (this.otherBounds != null) {
int length = this.superInterfaces.length;
int otherLength = this.otherBounds.length;
System.arraycopy(this.superInterfaces, 0, this.superInterfaces = new ReferenceBinding[length+otherLength], 0, length);
for (int i = 0; i < otherLength; i++) {
this.superInterfaces[length+i] = (ReferenceBinding) this.otherBounds[i];
}
}
}
}
return this.superInterfaces;
}
@Override
public void swapUnresolved(UnresolvedReferenceBinding unresolvedType, ReferenceBinding resolvedType, LookupEnvironment env) {
boolean affected = false;
if (this.genericType == unresolvedType) {
this.genericType = resolvedType;
affected = true;
}
if (this.bound == unresolvedType) {
this.bound = env.convertUnresolvedBinaryToRawType(resolvedType);
affected = true;
}
if (this.otherBounds != null) {
for (int i = 0, length = this.otherBounds.length; i < length; i++) {
if (this.otherBounds[i] == unresolvedType) {
this.otherBounds[i] = env.convertUnresolvedBinaryToRawType(resolvedType);
affected = true;
}
}
}
if (affected)
initialize(this.genericType, this.bound, this.otherBounds);
}
@Override
public String toString() {
if (this.hasTypeAnnotations())
return annotatedDebugName();
switch (this.boundKind) {
case Wildcard.UNBOUND :
return new String(TypeConstants.WILDCARD_NAME);
case Wildcard.EXTENDS :
if (this.otherBounds == null)
return new String(CharOperation.concat(TypeConstants.WILDCARD_NAME, TypeConstants.WILDCARD_EXTENDS, this.bound.debugName().toCharArray()));
StringBuffer buffer = new StringBuffer(this.bound.debugName());
for (int i = 0, length = this.otherBounds.length; i < length; i++) {
buffer.append('&').append(this.otherBounds[i].debugName());
}
return buffer.toString();
default:
return new String(CharOperation.concat(TypeConstants.WILDCARD_NAME, TypeConstants.WILDCARD_SUPER, this.bound.debugName().toCharArray()));
}
}
public TypeVariableBinding typeVariable() {
if (this.typeVariable == null) {
TypeVariableBinding[] typeVariables = this.genericType.typeVariables();
if (this.rank < typeVariables.length)
this.typeVariable = typeVariables[this.rank];
}
return this.typeVariable;
}
@Override
public TypeBinding unannotated() {
return this.hasTypeAnnotations() ? this.environment.getUnannotatedType(this) : this;
}
@Override
public TypeBinding withoutToplevelNullAnnotation() {
if (!hasNullTypeAnnotations())
return this;
AnnotationBinding[] newAnnotations = this.environment.filterNullTypeAnnotations(getTypeAnnotations());
return this.environment.createWildcard(this.genericType, this.rank, this.bound, this.otherBounds, this.boundKind, newAnnotations);
}
@Override
public TypeBinding uncapture(Scope scope) {
if ((this.tagBits & TagBits.HasCapturedWildcard) == 0)
return this;
TypeBinding freeBound = this.bound != null ? this.bound.uncapture(scope) : null;
int length = 0;
TypeBinding [] freeOtherBounds = this.otherBounds == null ? null : new TypeBinding[length = this.otherBounds.length];
for (int i = 0; i < length; i++) {
freeOtherBounds[i] = this.otherBounds[i] == null ? null : this.otherBounds[i].uncapture(scope);
}
return scope.environment().createWildcard(this.genericType, this.rank, freeBound, freeOtherBounds, this.boundKind, getTypeAnnotations());
}
@Override
void collectInferenceVariables(Set<InferenceVariable> variables) {
if (this.bound != null)
this.bound.collectInferenceVariables(variables);
if (this.otherBounds != null)
for (int i = 0, length = this.otherBounds.length; i < length; i++)
this.otherBounds[i].collectInferenceVariables(variables);
}
@Override
public boolean mentionsAny(TypeBinding[] parameters, int idx) {
if (this.inRecursiveFunction)
return false;
this.inRecursiveFunction = true;
try {
if (super.mentionsAny(parameters, idx))
return true;
if (this.bound != null && this.bound.mentionsAny(parameters, -1))
return true;
if (this.otherBounds != null) {
for (int i = 0, length = this.otherBounds.length; i < length; i++)
if (this.otherBounds[i].mentionsAny(parameters, -1))
return true;
}
} finally {
this.inRecursiveFunction = false;
}
return false;
}
@Override
public boolean acceptsNonNullDefault() {
return false;
}
@Override
public long updateTagBits() {
if (!this.inRecursiveFunction) {
this.inRecursiveFunction = true;
try {
if (this.bound != null)
this.tagBits |= this.bound.updateTagBits();
if (this.otherBounds != null) {
for (int i = 0, length = this.otherBounds.length; i < length; i++)
this.tagBits |= this.otherBounds[i].updateTagBits();
}
} finally {
this.inRecursiveFunction = false;
}
}
return super.updateTagBits();
}
}