Skip to content

Commit

Permalink
Manage prefix for extends and implements completion
Browse files Browse the repository at this point in the history
Recover the prefix in this case:

```java
public class MyClass ext| {
}
```

So that we know to only suggest `extends` and not `implements`.

Also, do not suggest `implements` for interfaces.

Signed-off-by: David Thompson <[email protected]>
  • Loading branch information
datho7561 committed Nov 6, 2024
1 parent 1784220 commit e114cb9
Showing 1 changed file with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -413,14 +413,24 @@ public void run() {
while (bodyStart < buffer.getLength() && buffer.getChar(bodyStart) != '{') {
bodyStart++;
}
int prefixCursor = this.offset;
while (prefixCursor > 0 && !Character.isWhitespace(buffer.getChar(prefixCursor - 1))) {
prefixCursor--;
}
this.prefix = buffer.getText(prefixCursor, this.offset - prefixCursor);
if (nameEndOffset < this.offset && this.offset <= bodyStart) {
String extendsOrImplementsContent = buffer.getText(nameEndOffset, this.offset - nameEndOffset);
if (extendsOrImplementsContent.indexOf("implements") < 0 && extendsOrImplementsContent.indexOf("extends") < 0) { //$NON-NLS-1$ //$NON-NLS-2$
// public class Foo | {
//
// }
this.requestor.accept(createKeywordProposal(Keywords.EXTENDS, this.offset, this.offset));
this.requestor.accept(createKeywordProposal(Keywords.IMPLEMENTS, this.offset, this.offset));
boolean isInterface = typeDecl instanceof TypeDeclaration realTypeDecl && realTypeDecl.isInterface();
if (CharOperation.prefixEquals(this.prefix.toCharArray(), Keywords.EXTENDS)) {
this.requestor.accept(createKeywordProposal(Keywords.EXTENDS, this.offset, this.offset));
}
if (!isInterface && CharOperation.prefixEquals(this.prefix.toCharArray(), Keywords.IMPLEMENTS)) {
this.requestor.accept(createKeywordProposal(Keywords.IMPLEMENTS, this.offset, this.offset));
}
} else if (extendsOrImplementsContent.indexOf("implements") < 0 && (Character.isWhitespace(buffer.getChar(this.offset - 1)) || buffer.getChar(this.offset - 1) == ',')) { //$NON-NLS-1$
// public class Foo extends Bar, Baz, | {
//
Expand Down

0 comments on commit e114cb9

Please sign in to comment.