GH-1429: find parent method or type declaration from within deeper nested ast nodes
Fixes GH-1429
This commit is contained in:
@@ -51,6 +51,10 @@ public class DependsOnCompletionProcessor implements AnnotationAttributeCompleti
|
||||
|
||||
private Collection<String> getBeanNameFromSourceCodePosition(ASTNode node) {
|
||||
ASTNode parent = node.getParent();
|
||||
while (parent != null && !(parent instanceof MethodDeclaration) && !(parent instanceof TypeDeclaration)) {
|
||||
parent = parent.getParent();
|
||||
}
|
||||
|
||||
if (parent instanceof MethodDeclaration method) {
|
||||
Annotation beanAnnotation = ASTUtils.getBeanAnnotation(method);
|
||||
return BeanUtils.getBeanNamesFromBeanAnnotation(beanAnnotation);
|
||||
|
||||
@@ -207,6 +207,14 @@ public class DependsOnCompletionProviderTest {
|
||||
assertCompletions("@DependsOn({\"bean1\",<*>\"bean2\"})", 1, "@DependsOn({\"bean1\",\"bean3\",<*>\"bean2\"})");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDependsOnCompletionWithinQuotesExcludeDefaultBeanNameFromComponent() throws Exception {
|
||||
Bean componentBean = new Bean("testDependsOnClass", "org.test.TestDependsOnClass", new Location(tempJavaDocUri, new Range(new Position(1,1), new Position(1, 20))), null, null, null, false);
|
||||
springIndex.updateBeans(project.getElementName(), new Bean[] {bean1, bean2, componentBean});
|
||||
|
||||
assertCompletions("@DependsOn(\"<*>\")", 2, "@DependsOn(\"bean1<*>\")");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDependsOnCompletionExcludeDefaultBeanNameFromComponent() throws Exception {
|
||||
Bean componentBean = new Bean("testDependsOnClass", "org.test.TestDependsOnClass", new Location(tempJavaDocUri, new Range(new Position(1,1), new Position(1, 20))), null, null, null, false);
|
||||
|
||||
Reference in New Issue
Block a user