Skip to content

Commit

Permalink
Improve field completion (name.|)
Browse files Browse the repository at this point in the history
- Use bindings to build out a list of possible suggestions
- Handle access modifiers properly (`private`, `static`, `abstract`, ...)
  - Exclude members in grandparent types whose access was narrowed in
    parent types
- Fix completion preceeding another statement eg.

```java
{
  name.|
  Object myObject = null;
}
```
- Fix `super.to|`
- Prevent `super.|` and `super.to|` from suggesting methods that are
  abstract in the parent type

Fixes eclipse-jdt#891

Signed-off-by: David Thompson <davthomp@redhat.com>
  • Loading branch information
datho7561 committed Dec 13, 2024
1 parent c84aee9 commit 212006a
Show file tree
Hide file tree
Showing 3 changed files with 216 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,7 @@ yield switch (rootCauseCode) {
case "compiler.err.cant.ref.before.ctor.called" -> IProblem.InstanceFieldDuringConstructorInvocation; // TODO different according to target node
case "compiler.err.not.def.public.cant.access" -> IProblem.NotVisibleType; // TODO different according to target node
case "compiler.err.already.defined" -> IProblem.DuplicateMethod; // TODO different according to target node
case "compiler.warn.underscore.as.identifier" -> IProblem.IllegalUseOfUnderscoreAsAnIdentifier;
case "compiler.err.var.might.not.have.been.initialized" -> {
VarSymbol symbol = getDiagnosticArgumentByType(diagnostic, VarSymbol.class);
yield symbol.owner instanceof ClassSymbol ?
Expand Down Expand Up @@ -1072,6 +1073,7 @@ yield switch (rootCauseCode) {
case "compiler.err.too.many.modules" -> IProblem.ModuleRelated;
case "compiler.err.call.must.only.appear.in.ctor" -> IProblem.InvalidExplicitConstructorCall;
case "compiler.err.void.not.allowed.here" -> IProblem.ParameterMismatch;
case "compiler.err.abstract.cant.be.accessed.directly" -> IProblem.DirectInvocationOfAbstractMethod;
default -> {
ILog.get().error("Could not accurately convert diagnostic (" + diagnostic.getCode() + ")\n" + diagnostic);
if (diagnostic.getKind() == javax.tools.Diagnostic.Kind.ERROR && diagnostic.getCode().startsWith("compiler.err")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

import java.util.function.Supplier;
import java.util.stream.Stream;

import org.eclipse.jdt.core.CompletionContext;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.Signature;
Expand Down Expand Up @@ -57,6 +56,9 @@ public IJavaElement getEnclosingElement() {
public IJavaElement[] getVisibleElements(String typeSignature) {
return this.bindingsAcquirer.get() //
.filter(binding -> {
if (typeSignature == null) {
return binding instanceof IVariableBinding || binding instanceof IMethodBinding;
}
if (binding instanceof IVariableBinding variableBinding) {
return castCompatable(variableBinding.getType(),
typeSignature);
Expand All @@ -69,6 +71,7 @@ public IJavaElement[] getVisibleElements(String typeSignature) {
return false;
}) //
.map(binding -> binding.getJavaElement()) //
.filter(obj -> obj != null) // eg. ArrayList.getFirst() when working with a Java 8 project
.toArray(IJavaElement[]::new);
}

Expand Down
Loading

0 comments on commit 212006a

Please sign in to comment.