Skip to content

Commit d107775

Browse files
datho7561mickaelistria
authored andcommitted
Fix CompletionTests.testBug385858c (bad context expected type signature)
- Fix calculation of signature of expected types in completion context. It wasn't handling inner types properly. - use our method from `SignatureUtils` to handle this - Handle "start of constructor" token location calculation (also related to completion context) Fixes 3 Signed-off-by: David Thompson <[email protected]>
1 parent c327e20 commit d107775

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
import org.eclipse.jdt.core.dom.StringLiteral;
5151
import org.eclipse.jdt.core.dom.TypeDeclaration;
5252
import org.eclipse.jdt.core.dom.VariableDeclaration;
53+
import org.eclipse.jdt.internal.SignatureUtils;
5354
import org.eclipse.jdt.internal.codeassist.DOMCompletionEngine.Bindings;
5455
import org.eclipse.jdt.internal.codeassist.impl.AssistOptions;
5556
import org.eclipse.jdt.internal.compiler.parser.RecoveryScanner;
@@ -282,10 +283,11 @@ public char[][] getExpectedTypesSignatures() {
282283
return null;
283284
}
284285
var res = this.expectedTypes.getExpectedTypes().stream() //
285-
.map(binding -> binding.isTypeVariable() ?
286-
'T' + binding.getQualifiedName() + ';' : binding.isLocal() ? Signature.createTypeSignature(binding.getName(), true) :
287-
Signature.createTypeSignature(binding.getQualifiedName(), true))
288-
.map(String::toCharArray) //
286+
.map(SignatureUtils::getSignatureChar)
287+
// .map(binding -> binding.isTypeVariable() ?
288+
// 'T' + binding.getQualifiedName() + ';' : binding.isLocal() ? Signature.createTypeSignature(binding.getName(), true) :
289+
// Signature.createTypeSignature(binding.getQualifiedName(), true))
290+
// .map(String::toCharArray) //
289291
.toArray(char[][]::new);
290292
return res.length == 0 ? null : res;
291293
}
@@ -303,7 +305,7 @@ public int getTokenLocation() {
303305
return TL_IN_IMPORT;
304306
}
305307
if (wrappingNode instanceof ClassInstanceCreation newObj) {
306-
return getTokenStart() <= newObj.getType().getStartPosition() ? TL_CONSTRUCTOR_START : 0;
308+
return getTokenStart() <= (newObj.getType().getStartPosition() + newObj.getType().getLength()) ? TL_CONSTRUCTOR_START : 0;
307309
}
308310
if (wrappingNode instanceof Statement stmt && getTokenStart() == stmt.getStartPosition()) {
309311
return getTokenStart() == stmt.getStartPosition() ? TL_STATEMENT_START : 0;
@@ -322,7 +324,7 @@ public int getTokenLocation() {
322324
if (wrappingNode instanceof Block block) {
323325
return block.statements().isEmpty() ? TL_STATEMENT_START : 0;
324326
}
325-
if( wrappingNode instanceof AnonymousClassDeclaration anon) {
327+
if (wrappingNode instanceof AnonymousClassDeclaration anon) {
326328
if(isWithinTypeDeclarationBody(wrappingNode, this.textContent, this.offset)) {
327329
return TL_MEMBER_START;
328330
}

0 commit comments

Comments
 (0)