Skip to content

Commit b4db532

Browse files
committed
Fix key for wildcard/extends type
If there is no bound on the WildcardType, should be `+Lextended/Type` or `-Lsuper/Type` If a bound is set on the wildcardType, should be `Ldeclaring/Type;{#rank};+Lextended/Type;` Fixes #1836
1 parent a086556 commit b4db532

File tree

4 files changed

+23
-19
lines changed

4 files changed

+23
-19
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ static void getKey(StringBuilder builder, MethodSymbol methodSymbol, ExecutableT
448448

449449
if (parentType != null) {
450450
JavacTypeBinding parentBinding = resolver.bindings.getTypeBinding(parentType);
451-
String parentKey = parentBinding.getKey(true, true);
451+
String parentKey = parentBinding.getKeyWithPossibleGenerics(parentType, parentType.tsym);
452452
builder.append(parentKey);
453453
} else {
454454
Symbol ownerSymbol = methodSymbol.owner;

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

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -456,10 +456,7 @@ private String computeKey() {
456456
return b3;
457457
}
458458
public String getKeyWithPossibleGenerics(Type t, TypeSymbol s) {
459-
return getKeyWithPossibleGenerics(t, s, tb -> tb != null ? tb.getKey() : KeyUtils.OBJECT_KEY);
460-
}
461-
private String getKeyWithPossibleGenerics(Type t, TypeSymbol s, Function<ITypeBinding, String> parameterizedCallback) {
462-
return getKeyWithPossibleGenerics(t, s, parameterizedCallback, false);
459+
return getKeyWithPossibleGenerics(t, s, tb -> tb != null ? tb.getKey() : KeyUtils.OBJECT_KEY, true);
463460
}
464461
private String getKeyWithPossibleGenerics(Type t, TypeSymbol s, Function<ITypeBinding, String> parameterizedCallback, boolean useSlashes) {
465462
if( !this.isGeneric && this instanceof JavacTypeVariableBinding jctvb ) {
@@ -734,19 +731,8 @@ static void getKey(StringBuilder builder, Type typeToBuild, String n, boolean is
734731
if ((b1 || b2) && includeParameters) {
735732
builder.append('<');
736733
for (var typeArgument : typeToBuild.getTypeArguments()) {
737-
StringBuilder tmp = new StringBuilder();
738-
getKey(tmp, typeArgument, typeArgument.asElement().flatName().toString(),
734+
getKey(builder, typeArgument, typeArgument.asElement().flatName().toString(),
739735
false, includeParameters, useSlashes, resolver);
740-
String paramType = tmp.toString();
741-
if( paramType.startsWith("+") && !paramType.equals("+Ljava/lang/Object;")) {
742-
builder.append("!");
743-
builder.append(currentTypeSignature);
744-
builder.append(";{1}");// TODO
745-
builder.append(paramType);
746-
builder.append("1;");// TODO
747-
} else {
748-
builder.append(paramType);
749-
}
750736
}
751737
builder.append('>');
752738
}

org.eclipse.jdt.core.tests.javac/src/org/eclipse/jdt/core/tests/javac/JavacSpecificConverterTests.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,22 @@ public <E extends Exception> void m() throws E {
9393
MethodDeclaration meth = (MethodDeclaration) NodeFinder.perform(node, source.indexOf("m()"), 0).getParent();
9494
assertEquals("LA;.m<E:Ljava/lang/Exception;>()V|TE;", meth.resolveBinding().getKey());
9595
}
96-
}
96+
97+
@Test
98+
public void testInvalidSignatureDeepTypeParameter() throws Exception {
99+
ASTParser parser = ASTParser.newParser(AST.getJLSLatest());
100+
String source = """
101+
interface A {
102+
java.util.List<java.util.List<? extends String>> m();
103+
}
104+
""";
105+
parser.setSource(source.toCharArray());
106+
parser.setUnitName("A.java");
107+
parser.setEnvironment(null, null, null, true);
108+
parser.setResolveBindings(true);
109+
ASTNode node = parser.createAST(new NullProgressMonitor());
110+
MethodDeclaration meth = (MethodDeclaration) NodeFinder.perform(node, source.indexOf("m()"), 0).getParent();
111+
assertEquals("LA;.m()Ljava/util/List<Ljava/util/List<+Ljava/lang/String;>;>;", meth.resolveBinding().getKey());
112+
}
113+
114+
}

org.eclipse.jdt.core.tests.javac/src/org/eclipse/jdt/core/tests/javac/RegressionTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ public void testGetModelForTypeWithAnnotation() throws Exception {
254254
IJavaProject javaProject = JavaCore.create(project);
255255
IType type = javaProject.findType("test.FieldWithAnnotatedType");
256256
IField theField = type.getFields()[0];
257-
String s = theField.getTypeSignature();
257+
theField.getTypeSignature(); // test no exception is thrown
258258
}
259259

260260
static IProject importProject(String locationInBundle) throws URISyntaxException, IOException, CoreException {

0 commit comments

Comments
 (0)