No bean completion proposals in type declaration block

This commit is contained in:
aboyko
2025-04-03 17:40:02 -04:00
parent cc3aead696
commit d5b21a7e8c
2 changed files with 52 additions and 1 deletions

View File

@@ -69,6 +69,15 @@ public class BeanCompletionProvider implements CompletionProvider {
&& (node instanceof SimpleName || node instanceof Block || node instanceof FieldAccess || node instanceof ThisExpression)) {
try {
// Should be inside the block but not inside type declaration block.
ASTNode block = node;
for (; block != null && !(block instanceof Block); block = block.getParent()) {
}
// Not inside the block? Or inside the Type Declaration block? Bail out!
if (block == null || block instanceof Block && block.getParent() instanceof TypeDeclaration) {
return;
}
if (node instanceof SimpleName) {
if (node.getParent() instanceof FieldAccess fa && !(fa.getExpression() instanceof ThisExpression)) {
return;

View File

@@ -1220,6 +1220,48 @@ public class TestBeanCompletionClass {
assertCompletions(content, new String[0], 0, null);
}
@Test
public void constructorNoCompletions_3() throws Exception {
String content = """
package org.sample.test;
import org.springframework.stereotype.Component;
@Component
public class Comp1 {
ow<*>
public Comp1() {
}
}
""";
assertCompletions(content, new String[0], 0, null);
}
@Test
public void constructorNoCompletions_4() throws Exception {
String content = """
package org.sample.test;
import org.springframework.stereotype.Component;
@Component
public class Comp1 {
ow<*>
Comp1() {
}
}
""";
assertCompletions(content, new String[0], 0, null);
}
private void assertCompletions(String completionLine, String[] expectedCompletions, int chosenCompletion, String expectedResult) throws Exception {
Editor editor = harness.newEditor(LanguageId.JAVA, completionLine, tempJavaDocUri);
@@ -1230,7 +1272,7 @@ public class TestBeanCompletionClass {
if (expectedCompletions != null) {
String[] completionItems = completions.stream()
.map(item -> item.getLabel())
.limit(expectedCompletions.length)
.limit(expectedCompletions.length == 0 ? Integer.MAX_VALUE : expectedCompletions.length)
.toArray(size -> new String[size]);
assertArrayEquals(expectedCompletions, completionItems);