From 901879da2d6116b98ff0659f6ef34f976049944a Mon Sep 17 00:00:00 2001 From: David Thompson Date: Fri, 29 Nov 2024 13:12:18 -0500 Subject: [PATCH] [WIP] show completions for statics Signed-off-by: David Thompson --- .../codeassist/DOMCompletionEngine.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) 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 4c501569de0..4ea147de5a8 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 @@ -752,6 +752,35 @@ private void scrapeAccessibleBindings(Bindings scope) { } current = current.getParent(); } + + // handle favourite members + + if (this.requestor.getFavoriteReferences() == null) { + return; + } + + List keysToResolve = new ArrayList<>(); + IJavaProject project = this.modelUnit.getJavaProject(); + for (String favouriteReference: this.requestor.getFavoriteReferences()) { + if (favouriteReference.endsWith(".*")) { //$NON-NLS-1$ + favouriteReference = favouriteReference.substring(0, favouriteReference.length() - 2); + } + String packageName = favouriteReference.substring(0, favouriteReference.lastIndexOf('.')); + String typeName = favouriteReference.substring(favouriteReference.lastIndexOf('.') + 1); + findTypes(typeName, SearchPattern.R_EXACT_MATCH, packageName).forEach(keysToResolve::add); + } + ASTParser parser = ASTParser.newParser(AST.getJLSLatest()); + parser.setProject(project); + if (!keysToResolve.isEmpty()) { + IBinding[] bindings = parser.createBindings(keysToResolve.toArray(IType[]::new), this.monitor); + for (IBinding binding : bindings) { + if (binding instanceof ITypeBinding typeBinding) { + processMembers(this.toComplete, typeBinding, scope, true); + } else { + ILog.get().warn("expected the favourite reference to be a Type"); //$NON-NLS-1$ + } + } + } } private void completeMethodModifiers(MethodDeclaration methodDeclaration) {