Skip to content

Commit 10593d0

Browse files
mickaelistriarobstryker
authored andcommitted
Improve getKey for wildcards
1 parent f0f564f commit 10593d0

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

org.eclipse.jdt.core.javac/src/org/eclipse/jdt/internal/javac/dom/JavacTypeBinding.java

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,32 @@ public String getKey() {
407407
}
408408

409409
private String computeKey() {
410+
if (isWildcardType() && this.type instanceof WildcardType wildcardType) {
411+
String key = getKey(wildcardType.bound.tsym.owner.asType(), wildcardType.bound.tsym.owner.flatName(), false, true);
412+
key += "{" + getRank() + "}";
413+
if (wildcardType.isUnbound()) {
414+
// This is very wrong and is not parseable by KeyToSignature
415+
// Should be something like Lg1/t/m/def/Generic;{0}*
416+
key = key + '+' + this.resolver.resolveWellKnownType(Object.class.getName()).getKey();
417+
} else if (wildcardType.isExtendsBound()) {
418+
Type extendsBound = wildcardType.getExtendsBound();
419+
if (extendsBound.isIntersection()) {
420+
key += '*';
421+
} else {
422+
key += '+';
423+
key += getBound().getKey();
424+
}
425+
} else if (wildcardType.isSuperBound()) {
426+
Type superBound = wildcardType.getSuperBound();
427+
if (superBound.isIntersection()) {
428+
key += '*';
429+
} else {
430+
key += '-';
431+
key += getBound().getKey();
432+
}
433+
}
434+
return key;
435+
}
410436
String b3 = getKeyWithPossibleGenerics(this.type, this.typeSymbol, tb -> tb != null ? tb.getKey() : KeyUtils.OBJECT_KEY, true);
411437
if( (this.type.isSuperBound() || this.type.isExtendsBound()) && this.type instanceof WildcardType wt) {
412438
String base1 = getKey(this.type, this.typeSymbol.flatName(), false, true);
@@ -808,7 +834,16 @@ public ITypeBinding getGenericTypeOfWildcardType() {
808834

809835
@Override
810836
public int getRank() {
811-
if (isWildcardType() || isIntersectionType()) {
837+
if (isWildcardType() && this.type instanceof WildcardType wildcardType) {
838+
var params = getDeclaringClass().getTypeParameters();
839+
for (int i = 0; i < params.length; i++) {
840+
var typeParam = params[i];
841+
if (typeParam instanceof JavacTypeBinding javacTypeParam && javacTypeParam.type == wildcardType.bound) {
842+
return i;
843+
}
844+
}
845+
}
846+
if (isIntersectionType()) {
812847
return types.rank(this.type);
813848
}
814849
return -1;
@@ -1402,6 +1437,9 @@ public ITypeBinding[] getTypeBounds() {
14021437

14031438
@Override
14041439
public ITypeBinding getTypeDeclaration() {
1440+
if (isWildcardType()) {
1441+
return this;
1442+
}
14051443
if (this.isParameterizedType() || this.isRawType()) {
14061444
return getErasure();
14071445
}

0 commit comments

Comments
 (0)