GH-1429: find parent method or type declaration from within deeper nested ast nodes

Fixes GH-1429
This commit is contained in:
Martin Lippert
2025-02-03 09:33:05 +01:00
parent 5f45c08071
commit 3824d67916
2 changed files with 12 additions and 0 deletions

View File

@@ -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);

View File

@@ -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);