X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;ds=sidebyside;f=src%2Forg%2Feclipse%2Fjdt%2Finternal%2Fcompiler%2Flookup%2FArrayBinding.java;fp=src%2Forg%2Feclipse%2Fjdt%2Finternal%2Fcompiler%2Flookup%2FArrayBinding.java;h=541002be435bac5a93542d7de4e8676722ed896a;hb=c17753cd9e62cd1a71df3d88af908de0425ac33d;hp=da456843bfd22dd2f5edc22b7972c67848afeb56;hpb=040fa5af2cd00017cf3575950cdaade34a6d7f6c;p=org.ibex.tool.git diff --git a/src/org/eclipse/jdt/internal/compiler/lookup/ArrayBinding.java b/src/org/eclipse/jdt/internal/compiler/lookup/ArrayBinding.java index da45684..541002b 100644 --- a/src/org/eclipse/jdt/internal/compiler/lookup/ArrayBinding.java +++ b/src/org/eclipse/jdt/internal/compiler/lookup/ArrayBinding.java @@ -10,6 +10,7 @@ *******************************************************************************/ package org.eclipse.jdt.internal.compiler.lookup; +import java.util.Map; import org.eclipse.jdt.core.compiler.CharOperation; import org.eclipse.jdt.internal.compiler.impl.Constant; @@ -20,19 +21,56 @@ public final class ArrayBinding extends TypeBinding { public TypeBinding leafComponentType; public int dimensions; - + LookupEnvironment environment; char[] constantPoolName; -public ArrayBinding(TypeBinding type, int dimensions) { + char[] genericTypeSignature; + +public ArrayBinding(TypeBinding type, int dimensions, LookupEnvironment environment) { this.tagBits |= IsArrayType; this.leafComponentType = type; this.dimensions = dimensions; + this.environment = environment; + if (type instanceof UnresolvedReferenceBinding) + ((UnresolvedReferenceBinding) type).addWrapper(this); + else + this.tagBits |= type.tagBits & (HasTypeVariable | HasDirectWildcard); +} + +public int kind() { + return ARRAY_TYPE; +} + +/** + * Collect the substitutes into a map for certain type variables inside the receiver type + * e.g. Collection.findSubstitute(T, Collection>): T --> List + */ +public void collectSubstitutes(TypeBinding otherType, Map substitutes) { + if (otherType.isArrayType()) { + int otherDim = otherType.dimensions(); + if (otherDim == this.dimensions) { + this.leafComponentType.collectSubstitutes(otherType.leafComponentType(), substitutes); + } else if (otherDim > this.dimensions) { + ArrayBinding otherReducedType = this.environment.createArrayType(otherType.leafComponentType(), otherDim - this.dimensions); + this.leafComponentType.collectSubstitutes(otherReducedType, substitutes); + } + } } + +/* + * brakets leafUniqueKey + * p.X[][] --> [[Lp/X; + */ +public char[] computeUniqueKey() { + char[] brackets = new char[dimensions]; + for (int i = dimensions - 1; i >= 0; i--) brackets[i] = '['; + return CharOperation.concat(brackets, this.leafComponentType.computeUniqueKey()); + } + /** * Answer the receiver's constant pool name. * NOTE: This method should only be used during/after code gen. * e.g. '[Ljava/lang/Object;' */ - public char[] constantPoolName() { if (constantPoolName != null) return constantPoolName; @@ -41,7 +79,7 @@ public char[] constantPoolName() { for (int i = dimensions - 1; i >= 0; i--) brackets[i] = '['; return constantPoolName = CharOperation.concat(brackets, leafComponentType.signature()); } -String debugName() { +public String debugName() { StringBuffer brackets = new StringBuffer(dimensions * 2); for (int i = dimensions; --i >= 0;) brackets.append("[]"); //$NON-NLS-1$ @@ -56,16 +94,41 @@ public int dimensions() { * When the receiver's dimension size is one then answer the leaf component type. */ -public TypeBinding elementsType(Scope scope) { - if (dimensions == 1) return leafComponentType; - return scope.createArray(leafComponentType, dimensions - 1); +public TypeBinding elementsType() { + if (this.dimensions == 1) return this.leafComponentType; + return this.environment.createArrayType(this.leafComponentType, this.dimensions - 1); } +/** + * @see org.eclipse.jdt.internal.compiler.lookup.TypeBinding#erasure() + */ +public TypeBinding erasure() { + TypeBinding erasedType = this.leafComponentType.erasure(); + if (this.leafComponentType != erasedType) + return this.environment.createArrayType(erasedType, this.dimensions); + return this; +} +public LookupEnvironment environment() { + return this.environment; +} + +public char[] genericTypeSignature() { + + if (this.genericTypeSignature == null) { + char[] brackets = new char[dimensions]; + for (int i = dimensions - 1; i >= 0; i--) brackets[i] = '['; + this.genericTypeSignature = CharOperation.concat(brackets, leafComponentType.genericTypeSignature()); + } + return this.genericTypeSignature; +} + public PackageBinding getPackage() { return leafComponentType.getPackage(); } +public int hashCode() { + return this.leafComponentType == null ? super.hashCode() : this.leafComponentType.hashCode(); +} /* Answer true if the receiver type can be assigned to the argument type (right) */ - public boolean isCompatibleWith(TypeBinding right) { if (this == right) return true; @@ -81,6 +144,9 @@ public boolean isCompatibleWith(TypeBinding right) { } else { if (right.isBaseType()) return false; + if (right.isWildcard()) { + return ((WildcardBinding) right).boundCheck(this); + } } //Check dimensions - Java does not support explicitly sized dimensions for types. //However, if it did, the type checking support would go here. @@ -143,6 +209,12 @@ public char[] sourceName() { } return CharOperation.concat(leafComponentType.sourceName(), brackets); } +public void swapUnresolved(UnresolvedReferenceBinding unresolvedType, ReferenceBinding resolvedType, LookupEnvironment env) { + if (this.leafComponentType == unresolvedType) { + this.leafComponentType = resolvedType.isGenericType() ? env.createRawType(resolvedType, resolvedType.enclosingType()) : resolvedType; + this.tagBits |= this.leafComponentType.tagBits & (HasTypeVariable | HasDirectWildcard); + } +} public String toString() { return leafComponentType != null ? debugName() : "NULL TYPE ARRAY"; //$NON-NLS-1$ }