From 4b6de2ff952a27cafabfe7e8c0267290edfa60b9 Mon Sep 17 00:00:00 2001 From: Gayan Perera Date: Sun, 7 Jul 2024 20:34:05 +0200 Subject: [PATCH] add import required proposal for type completions --- .../codeassist/DOMCompletionEngine.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/DOMCompletionEngine.java b/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/DOMCompletionEngine.java index ef197c4e465..31d6933a370 100644 --- a/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/DOMCompletionEngine.java +++ b/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/DOMCompletionEngine.java @@ -462,9 +462,12 @@ private String qualifiedTypeName(ITypeBinding typeBinding) { private CompletionProposal toProposal(IType type) { // TODO add import if necessary InternalCompletionProposal res = new InternalCompletionProposal(CompletionProposal.TYPE_REF, this.offset); - res.setName(type.getElementName().toCharArray()); + char[] simpleName = type.getElementName().toCharArray(); + char[] signature = Signature.createTypeSignature(type.getFullyQualifiedName(), true).toCharArray(); + + res.setName(simpleName); res.setCompletion(type.getElementName().toCharArray()); - res.setSignature(Signature.createTypeSignature(type.getFullyQualifiedName(), true).toCharArray()); + res.setSignature(signature); res.setReplaceRange(!(this.toComplete instanceof FieldAccess) ? this.toComplete.getStartPosition() : this.offset, this.offset); try { res.setFlags(type.getFlags()); @@ -477,6 +480,16 @@ private CompletionProposal toProposal(IType type) { res.completionEngine = this.nestedEngine; res.nameLookup = this.nameEnvironment.nameLookup; // set defaults for now to avoid error downstream + res.setRequiredProposals(new CompletionProposal[] { toImportProposal(simpleName, signature) }); + return res; + } + + private CompletionProposal toImportProposal(char[] simpleName, char[] signature) { + InternalCompletionProposal res = new InternalCompletionProposal(CompletionProposal.TYPE_IMPORT, this.offset); + res.setName(simpleName); + res.setSignature(signature); + res.completionEngine = this.nestedEngine; + res.nameLookup = this.nameEnvironment.nameLookup; res.setRequiredProposals(new CompletionProposal[0]); return res; }