Fix bean completion invocation case
This commit is contained in:
@@ -66,7 +66,7 @@ public class BeanCompletionProvider implements CompletionProvider {
|
||||
@Override
|
||||
public void provideCompletions(ASTNode node, int offset, TextDocument doc, Collection<ICompletionProposal> completions) {
|
||||
if (config.isBeanInjectionCompletionEnabled()
|
||||
&& (node instanceof SimpleName || node instanceof Block || node instanceof FieldAccess)) {
|
||||
&& (node instanceof SimpleName || node instanceof Block || node instanceof FieldAccess || node instanceof ThisExpression)) {
|
||||
try {
|
||||
|
||||
if (node instanceof SimpleName) {
|
||||
|
||||
@@ -21,6 +21,7 @@ import org.eclipse.jdt.core.dom.CompilationUnit;
|
||||
import org.eclipse.jdt.core.dom.ITypeBinding;
|
||||
import org.eclipse.jdt.core.dom.NodeFinder;
|
||||
import org.eclipse.jdt.core.dom.SimpleName;
|
||||
import org.eclipse.jdt.core.dom.ThisExpression;
|
||||
import org.springframework.ide.vscode.boot.java.snippets.JavaSnippetManager;
|
||||
import org.springframework.ide.vscode.boot.java.utils.CompilationUnitCache;
|
||||
import org.springframework.ide.vscode.commons.languageserver.completion.ICompletionEngine;
|
||||
@@ -90,7 +91,8 @@ public class BootJavaCompletionEngine implements ICompletionEngine, LanguageSpec
|
||||
|
||||
if (numberOfSpaces > 0) {
|
||||
ASTNode leftNode = NodeFinder.perform(cu, offset - numberOfSpaces, 0);
|
||||
if (leftNode instanceof SimpleName && $MISSING$.equals(((SimpleName)leftNode).getIdentifier())) {
|
||||
if ((leftNode instanceof SimpleName && $MISSING$.equals(((SimpleName)leftNode).getIdentifier()))
|
||||
|| leftNode instanceof ThisExpression) {
|
||||
node = leftNode;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1069,6 +1069,47 @@ public class TestBeanCompletionClass {
|
||||
""");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void methodReturnStatementAfterThisStatementWithoutPrefix() throws Exception {
|
||||
String content = """
|
||||
package org.sample.test;
|
||||
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
public class TestBeanCompletionClass {
|
||||
String TestBeanCompletionClass() {
|
||||
this.<*>
|
||||
return new String("oo");
|
||||
}
|
||||
}
|
||||
""";
|
||||
|
||||
|
||||
assertCompletions(content, new String[] {"ownerRepository", "ownerService", "petService", "testIntBean", "visitRepository", "visitService"}, 0,
|
||||
"""
|
||||
package org.sample.test;
|
||||
|
||||
import org.springframework.samples.petclinic.owner.OwnerRepository;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
public class TestBeanCompletionClass {
|
||||
|
||||
private final OwnerRepository ownerRepository;
|
||||
|
||||
TestBeanCompletionClass(OwnerRepository ownerRepository) {
|
||||
this.ownerRepository = ownerRepository;
|
||||
}
|
||||
String TestBeanCompletionClass() {
|
||||
this.ownerRepository<*>
|
||||
return new String("oo");
|
||||
}
|
||||
}
|
||||
""");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void constructorNoThisNoPrefix() throws Exception {
|
||||
String content = """
|
||||
|
||||
Reference in New Issue
Block a user