### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: model/org/eclipse/jdt/core/BindingKey.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/core/BindingKey.java,v retrieving revision 1.22 diff -u -r1.22 BindingKey.java --- model/org/eclipse/jdt/core/BindingKey.java 27 Jun 2008 16:04:01 -0000 1.22 +++ model/org/eclipse/jdt/core/BindingKey.java 20 Jan 2009 11:50:15 -0000 @@ -10,6 +10,7 @@ *******************************************************************************/ package org.eclipse.jdt.core; +import org.eclipse.jdt.internal.compiler.lookup.TypeConstants; import org.eclipse.jdt.internal.core.util.KeyKind; import org.eclipse.jdt.internal.core.util.KeyToSignature; @@ -169,9 +170,12 @@ * @param typeKey the binding key of the given type * @param kind one of {@link Signature#C_STAR}, {@link Signature#C_SUPER}, or {@link Signature#C_EXTENDS} * @return a new wildcard type binding key + * @deprecated This method is missing crucial information necessary for proper wildcard binding key creation. + * @see org.eclipse.jdt.core.BindingKey#createWildcardTypeBindingKey(String, char, String, int) */ public static String createWilcardTypeBindingKey(String typeKey, char kind) { - // Note this implementation is heavily dependent on WildcardBinding#computeUniqueKey() + // Note this implementation is supposed to closely follow the behavior in WildcardBinding#computeUniqueKey() + // but it doesn't and hence the deprecation. See https://bugs.eclipse.org/bugs/show_bug.cgi?id=234609 switch (kind) { case Signature.C_STAR: return "*"; //$NON-NLS-1$ @@ -184,6 +188,49 @@ } /** + * Creates a new wildcard type binding key from the given generic type binding key, the given wildcard + * kind (one of {@link Signature#C_STAR}, {@link Signature#C_SUPER}, or {@link Signature#C_EXTENDS} + * the given bound type binding key and the given rank. If the wildcard kind is {@link Signature#C_STAR}, + * the given bound type binding key is ignored. + *
+ * For example: + *
+ *
+ * createWildcardTypeBindingKey("Ljava/util/ArrayList;", Signature.C_STAR, null, 0) -> "Ljava/util/ArrayList;{0}*"
+ * createWildcardTypeBindingKey("Ljava/util/ArrayList;", Signature.C_SUPER, "Ljava/lang/String;", 0) -> "Ljava/util/ArrayList;{0}-Ljava/lang/String;"
+ * createWildcardTypeBindingKey("Ljava/util/HashMap;", Signature.C_EXTENDS, "Ljava/lang/String;", 1) ->
+ * "Ljava/util/HashMap;{1}+Ljava/lang/String;"
+ *
+ *
+ *
+ *
+ * @param genericTypeKey the binding key of the generic type
+ * @param boundKind one of {@link Signature#C_STAR}, {@link Signature#C_SUPER}, or {@link Signature#C_EXTENDS}
+ * @param boundTypeKey the binding key of the bounding type.
+ * @param rank the relative position of this wild card type in the parameterization of the generic type.
+ * @return a new wildcard type binding key
+ */
+
+ public static String createWildcardTypeBindingKey(String genericTypeKey, char boundKind, String boundTypeKey, int rank) {
+ // Note this implementation is heavily dependent on WildcardBinding#computeUniqueKey()
+ String wildCardKey;
+ switch (boundKind) {
+ case Signature.C_STAR:
+ wildCardKey = new String(TypeConstants.WILDCARD_STAR);
+ break;
+ case Signature.C_SUPER:
+ wildCardKey = new String(TypeConstants.WILDCARD_MINUS) + boundTypeKey;
+ break;
+ case Signature.C_EXTENDS:
+ wildCardKey = new String(TypeConstants.WILDCARD_PLUS) + boundTypeKey;
+ break;
+ default:
+ return null;
+ }
+ return genericTypeKey + '{' + rank + '}' + wildCardKey;
+ }
+
+ /**
* Returns the thrown exception signatures of the element represented by this binding key.
* If this binding key does not represent a method or does not throw any exception,
* returns an empty array.
Index: dom/org/eclipse/jdt/core/dom/TypeBinding.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/TypeBinding.java,v
retrieving revision 1.143
diff -u -r1.143 TypeBinding.java
--- dom/org/eclipse/jdt/core/dom/TypeBinding.java 6 Oct 2008 13:23:51 -0000 1.143
+++ dom/org/eclipse/jdt/core/dom/TypeBinding.java 20 Jan 2009 11:50:14 -0000
@@ -163,7 +163,37 @@
}
return null;
}
-
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jdt.core.dom.ITypeBinding#getGenericType()
+ */
+ public ITypeBinding getGenericType() {
+ switch (this.binding.kind()) {
+ case Binding.WILDCARD_TYPE :
+ case Binding.INTERSECTION_TYPE :
+ WildcardBinding wildcardBinding = (WildcardBinding) this.binding;
+ if (wildcardBinding.genericType != null) {
+ return this.resolver.getTypeBinding(wildcardBinding.genericType);
+ }
+ break;
+ }
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jdt.core.dom.ITypeBinding#getRank()
+ */
+ public int getRank() {
+ switch (this.binding.kind()) {
+ case Binding.WILDCARD_TYPE :
+ case Binding.INTERSECTION_TYPE :
+ WildcardBinding wildcardBinding = (WildcardBinding) this.binding;
+ return wildcardBinding.rank;
+ default:
+ return -1;
+ }
+ }
+
/*
* @see ITypeBinding#getComponentType()
*/
Index: dom/org/eclipse/jdt/core/dom/ITypeBinding.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ITypeBinding.java,v
retrieving revision 1.72
diff -u -r1.72 ITypeBinding.java
--- dom/org/eclipse/jdt/core/dom/ITypeBinding.java 27 Jun 2008 16:03:46 -0000 1.72
+++ dom/org/eclipse/jdt/core/dom/ITypeBinding.java 20 Jan 2009 11:50:11 -0000
@@ -89,8 +89,29 @@
* @since 3.1
*/
public ITypeBinding getBound();
+
+ /**
+ * Returns the generic type associated with this wildcard type, if it has one.
+ * Returns null
if this is not a wildcard type.
+ *
+ * @return the generic type associated with this wildcard type, or null
if none
+ * @see #isWildcardType()
+ * @since 3.5
+ */
+ public ITypeBinding getGenericType();
/**
+ * Returns the rank associated with this wildcard type. The rank of this wild card type is the relative
+ * position of the wild card type in the parameterization of the associated generic type.
+ * Returns -1
if this is not a wildcard type.
+ *
+ * @return the rank associated with this wildcard type, or -1
if none
+ * @see #isWildcardType()
+ * @since 3.5
+ */
+ public int getRank();
+
+ /**
* Returns the binding representing the component type of this array type,
* or null
if this is not an array type binding. The component
* type of an array might be an array type.
Index: dom/org/eclipse/jdt/core/dom/RecoveredTypeBinding.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/RecoveredTypeBinding.java,v
retrieving revision 1.11
diff -u -r1.11 RecoveredTypeBinding.java
--- dom/org/eclipse/jdt/core/dom/RecoveredTypeBinding.java 27 Jun 2008 16:03:46 -0000 1.11
+++ dom/org/eclipse/jdt/core/dom/RecoveredTypeBinding.java 20 Jan 2009 11:50:12 -0000
@@ -89,6 +89,20 @@
}
/* (non-Javadoc)
+ * @see org.eclipse.jdt.core.dom.ITypeBinding#getGenericType()
+ */
+ public ITypeBinding getGenericType() {
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jdt.core.dom.ITypeBinding#getRank()
+ */
+ public int getRank() {
+ return -1;
+ }
+
+ /* (non-Javadoc)
* @see org.eclipse.jdt.core.dom.ITypeBinding#getComponentType()
*/
public ITypeBinding getComponentType() {
Index: model/org/eclipse/jdt/internal/core/util/BindingKeyParser.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/util/BindingKeyParser.java,v
retrieving revision 1.37
diff -u -r1.37 BindingKeyParser.java
--- model/org/eclipse/jdt/internal/core/util/BindingKeyParser.java 27 Jun 2008 16:03:57 -0000 1.37
+++ model/org/eclipse/jdt/internal/core/util/BindingKeyParser.java 20 Jan 2009 11:50:16 -0000
@@ -111,7 +111,7 @@
boolean isAtWildcardStart() {
return
this.index < this.source.length
- && "*+-".indexOf(this.source[this.index]) != -1; //$NON-NLS-1$
+ && this.source[this.index] == '{'; // e.g {1}+Ljava/lang/String;
}
boolean isAtTypeParameterStart() {
@@ -339,6 +339,12 @@
}
}
+ void skipRank() {
+ this.start = this.index;
+ while (this.index < this.source.length && "0123456789".indexOf(this.source[this.index]) != -1) //$NON-NLS-1$
+ this.index++;
+ }
+
void skipThrownStart() {
while (this.index < this.source.length && this.source[this.index] == C_THROWN)
this.index++;
@@ -359,6 +365,17 @@
if (this.index < this.source.length && this.source[this.index] == ';')
this.index++;
}
+
+ void skipRankStart() {
+ if (this.index < this.source.length && this.source[this.index] == '{')
+ this.index++;
+ }
+
+ void skipRankEnd() {
+ if (this.index < this.source.length && this.source[this.index] == '}')
+ this.index++;
+ this.start = this.index;
+ }
public String toString() {
StringBuffer buffer = new StringBuffer();
@@ -543,6 +560,10 @@
public void consumeWildCard(int kind) {
// default is to do nothing
}
+
+ public void consumeWildcardRank(int rank) {
+ // default is to do nothing
+ }
/*
* Returns the string that this binding key wraps.
@@ -883,6 +904,7 @@
}
private void parseWildcard() {
+ parseWildcardRank();
if (this.scanner.nextToken() != Scanner.WILDCARD) return;
char[] source = this.scanner.getTokenSource();
if (source.length == 0) {
@@ -910,6 +932,14 @@
consumeWildCard(kind);
}
+ private void parseWildcardRank() {
+ this.scanner.skipRankStart();
+ this.scanner.skipRank();
+ char[] source = this.scanner.getTokenSource();
+ consumeWildcardRank(Integer.parseInt(new String(source)));
+ this.scanner.skipRankEnd();
+ }
+
private void parseWildcardBound() {
BindingKeyParser parser = newParser();
parser.parse();
Index: model/org/eclipse/jdt/internal/core/util/BindingKeyResolver.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/util/BindingKeyResolver.java,v
retrieving revision 1.53
diff -u -r1.53 BindingKeyResolver.java
--- model/org/eclipse/jdt/internal/core/util/BindingKeyResolver.java 27 Jun 2008 16:03:56 -0000 1.53
+++ model/org/eclipse/jdt/internal/core/util/BindingKeyResolver.java 20 Jan 2009 11:50:17 -0000
@@ -64,8 +64,7 @@
TypeBinding typeBinding;
TypeDeclaration typeDeclaration;
ArrayList types = new ArrayList();
- int rank = 0;
-
+
int wildcardRank;
CompilationUnitDeclaration outerMostParsedUnit;
@@ -75,11 +74,10 @@
*/
HashtableOfObject resolvedUnits;
- private BindingKeyResolver(BindingKeyParser parser, Compiler compiler, LookupEnvironment environment, int wildcardRank, CompilationUnitDeclaration outerMostParsedUnit, HashtableOfObject parsedUnits) {
+ private BindingKeyResolver(BindingKeyParser parser, Compiler compiler, LookupEnvironment environment, CompilationUnitDeclaration outerMostParsedUnit, HashtableOfObject parsedUnits) {
super(parser);
this.compiler = compiler;
this.environment = environment;
- this.wildcardRank = wildcardRank;
this.outerMostParsedUnit = outerMostParsedUnit;
this.resolvedUnits = parsedUnits;
}
@@ -349,8 +347,6 @@
public void consumeParser(BindingKeyParser parser) {
this.types.add(parser);
- if (((BindingKeyResolver) parser).compilerBinding instanceof WildcardBinding)
- this.rank++;
}
public void consumeScope(int scopeNumber) {
@@ -430,6 +426,10 @@
this.typeBinding =(TypeBinding) resolver.compilerBinding;
}
+ public void consumeWildcardRank(int aRank) {
+ this.wildcardRank = aRank;
+ }
+
public void consumeWildCard(int kind) {
switch (kind) {
case Wildcard.EXTENDS:
@@ -438,7 +438,7 @@
this.typeBinding = this.environment.createWildcard((ReferenceBinding) this.typeBinding, this.wildcardRank, (TypeBinding) boundResolver.compilerBinding, null /*no extra bound*/, kind);
break;
case Wildcard.UNBOUND:
- this.typeBinding = this.environment.createWildcard((ReferenceBinding) this.typeBinding, this.rank++, null/*no bound*/, null /*no extra bound*/, kind);
+ this.typeBinding = this.environment.createWildcard((ReferenceBinding) this.typeBinding, this.wildcardRank, null/*no bound*/, null /*no extra bound*/, kind);
break;
}
}
@@ -576,7 +576,7 @@
}
public BindingKeyParser newParser() {
- return new BindingKeyResolver(this, this.compiler, this.environment, this.rank, this.outerMostParsedUnit == null ? this.parsedUnit : this.outerMostParsedUnit, this.resolvedUnits);
+ return new BindingKeyResolver(this, this.compiler, this.environment, this.outerMostParsedUnit == null ? this.parsedUnit : this.outerMostParsedUnit, this.resolvedUnits);
}
public String toString() {
Index: compiler/org/eclipse/jdt/internal/compiler/lookup/WildcardBinding.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/WildcardBinding.java,v
retrieving revision 1.70
diff -u -r1.70 WildcardBinding.java
--- compiler/org/eclipse/jdt/internal/compiler/lookup/WildcardBinding.java 27 Jun 2008 16:04:02 -0000 1.70
+++ compiler/org/eclipse/jdt/internal/compiler/lookup/WildcardBinding.java 20 Jan 2009 11:50:09 -0000
@@ -23,8 +23,8 @@
*/
public class WildcardBinding extends ReferenceBinding {
- ReferenceBinding genericType;
- int rank;
+ public ReferenceBinding genericType;
+ public int rank;
public TypeBinding bound; // when unbound denotes the corresponding type variable (so as to retrieve its bound lazily)
public TypeBinding[] otherBounds; // only positionned by lub computations (if so, #bound is also set) and associated to EXTENDS mode
char[] genericSignature;
@@ -341,12 +341,14 @@
}
/*
- * genericTypeKey *|+|- [boundKey]
- * p.X