From 493f04022267b6293b5443928cfcbadaef22979b Mon Sep 17 00:00:00 2001 From: David Thompson Date: Tue, 5 Nov 2024 11:51:10 -0500 Subject: [PATCH] Fix some regressions caused by field access fix - `myMethod().|` - completion after method declaration in `@interface` Signed-off-by: David Thompson --- .../codeassist/DOMCompletionEngine.java | 22 +++++++++++++++++++ 1 file changed, 22 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 12f5eea1ce5..1409e7460ae 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 @@ -258,6 +258,14 @@ public void run() { completeAfter = fieldAccess.getName().toString(); } else if (this.toComplete instanceof MethodInvocation methodInvocation) { completeAfter = methodInvocation.getName().toString(); + try { + IBuffer cuBuffer = this.modelUnit.getBuffer(); + if (cuBuffer.getChar(this.offset - 1) == '.') { + completeAfter = ""; //$NON-NLS-1$ + } + } catch (JavaModelException e) { + ILog.get().error("error while trying to read buffer for completion purposes", e); //$NON-NLS-1$ + } } this.prefix = completeAfter; this.qualifiedPrefix = this.prefix; @@ -320,6 +328,17 @@ public void run() { .forEach(this.requestor::accept); } suggestDefaultCompletions = false; + } else if (invocation.getName().getStartPosition() + invocation.getName().getLength() + 3 /* the three chars: `().` */ <= this.offset && this.prefix.isEmpty()) { + // handle `myMethod().|` + IMethodBinding methodBinding = invocation.resolveMethodBinding(); + if (methodBinding != null) { + ITypeBinding returnType = methodBinding.getReturnType(); + processMembers(invocation, returnType, specificCompletionBindings, false); + specificCompletionBindings.stream() + .map(binding -> toProposal(binding)) + .forEach(this.requestor::accept); + } + suggestDefaultCompletions = false; } } if (context instanceof VariableDeclaration declaration) { @@ -358,6 +377,9 @@ public void run() { if (context.getParent() instanceof MethodDeclaration) { suggestDefaultCompletions = false; } + if (context.getParent() instanceof AnnotationTypeMemberDeclaration) { + suggestDefaultCompletions = false; + } if (context.getLocationInParent().getId().equals(QualifiedName.QUALIFIER_PROPERTY.getId()) && context.getParent() instanceof QualifiedName) { // eg. // void myMethod() {