Skip to content

Commit 783a30d

Browse files
datho7561rgrunber
authored andcommitted
Fix bad method signature
Uses a regex to strip some extra information that's present in keys but not signatures. Includes a new test case to cover this behaviour, since there is no existing test for this. Includes an unrelated fix (relevance number when a raw type is expected) to get the new test case passing. Fixes #1414 Signed-off-by: David Thompson <[email protected]>
1 parent f2a6d0e commit 783a30d

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

org.eclipse.jdt.core.javac/src/org/eclipse/jdt/internal/SignatureUtils.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,11 +189,14 @@ public static String getSignatureForMethodKey(String key) {
189189
.replace("<+Ljava.lang.Object;>", "<*>");
190190
String removeName = fullKey.substring(fullKey.indexOf('('));
191191
int firstException = removeName.indexOf('|');
192+
String exceptionRemoved;
192193
if (firstException > 0) {
193-
return removeName.substring(0, firstException);
194+
exceptionRemoved = removeName.substring(0, firstException);
194195
} else {
195-
return removeName;
196+
exceptionRemoved = removeName;
196197
}
198+
// strip out the weird information the keys need to differentiate themselves
199+
return exceptionRemoved.replaceAll("!L[^;]+;\\{[0-9]+\\}(\\+L[^;]+;)[0-9]+;", "$1");
197200
}
198201

199202
public static String stripTypeArgumentsFromKey(String key) {

org.eclipse.jdt.core.javac/src/org/eclipse/jdt/internal/codeassist/RelevanceUtils.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ static int computeRelevanceForExpectingType(ITypeBinding proposalType, ExpectedT
109109

110110
if(Objects.equals(expectedType.getQualifiedName(), proposalType.getQualifiedName())) {
111111
return RelevanceConstants.R_EXACT_EXPECTED_TYPE;
112+
} else if (expectedType.isRawType() && Objects.equals(expectedType.getErasure().getQualifiedName(), proposalType.getErasure().getQualifiedName())) {
113+
return RelevanceConstants.R_EXACT_EXPECTED_TYPE;
112114
} else if (proposalType.getPackage() != null && proposalType.getPackage().isUnnamed()) {
113115
return RelevanceConstants.R_PACKAGE_EXPECTED_TYPE;
114116
}

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -635,4 +635,32 @@ void m() {
635635
hashCode[METHOD_REF]{hashCode(), Ljava.lang.Object;, ()I, hashCode, [201, 201], 79}""", requestor.getResults());
636636
}
637637

638+
@Test
639+
public void testCompleteMethodWithWildcardReturnType() throws Exception {
640+
this.workingCopies = new ICompilationUnit[1];
641+
this.workingCopies[0] = getWorkingCopy("HelloWorld.java",
642+
"""
643+
import java.util.List;
644+
645+
public class HelloWorld {
646+
public List<? extends String> getMyList() {
647+
return List.of();
648+
}
649+
void m() {
650+
List myList = getMyLi
651+
}
652+
}
653+
""");
654+
655+
CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(false, false, true);
656+
657+
String str = this.workingCopies[0].getSource();
658+
String completeBehind = "getMyLi";
659+
int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
660+
IProgressMonitor monitor = new NullProgressMonitor();
661+
this.workingCopies[0].codeComplete(cursorLocation, requestor, WC_OWNER, monitor);
662+
assertEquals("""
663+
getMyList[METHOD_REF]{getMyList(), LHelloWorld;, ()Ljava.util.List<+Ljava.lang.String;>;, getMyList, [147, 154], 82}""", requestor.getResults());
664+
}
665+
638666
}

0 commit comments

Comments
 (0)