Skip to content

Commit 4588b08

Browse files
committed
GH-1499: do not check bean registrar imports when it is not a bean registrar implementation
1 parent f4d67bd commit 4588b08

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/reconcilers/BeanRegistrarDeclarationReconciler.java

+6
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import java.util.Arrays;
1717
import java.util.List;
1818
import java.util.Map;
19+
import java.util.Set;
1920
import java.util.stream.Collectors;
2021
import java.util.stream.Stream;
2122

@@ -26,6 +27,7 @@
2627
import org.springframework.ide.vscode.boot.index.SpringMetamodelIndex;
2728
import org.springframework.ide.vscode.boot.java.Annotations;
2829
import org.springframework.ide.vscode.boot.java.Boot4JavaProblemType;
30+
import org.springframework.ide.vscode.boot.java.utils.ASTUtils;
2931
import org.springframework.ide.vscode.commons.Version;
3032
import org.springframework.ide.vscode.commons.java.IClasspathUtil;
3133
import org.springframework.ide.vscode.commons.java.IJavaProject;
@@ -73,6 +75,10 @@ public boolean visit(TypeDeclaration node) {
7375
return true;
7476
}
7577

78+
if (ASTUtils.findInTypeHierarchy(type, Set.of(Annotations.BEAN_REGISTRAR_INTERFACE)) == null) {
79+
return true;
80+
}
81+
7682
List<Bean> configBeans = new ArrayList<>();
7783
Path p = Path.of(docURI);
7884
List<Path> sourceFolders = IClasspathUtil.getSourceFolders(project.getClasspath()).map(f -> f.toPath()).filter(f -> p.startsWith(f)).collect(Collectors.toList());

headless-services/spring-boot-language-server/src/test/java/org/springframework/ide/vscode/boot/java/reconcilers/test/BeanRegistrarDeclarationReconcilerTest.java

+27
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,33 @@ protected JdtAstReconciler getReconciler() {
5858
return new BeanRegistrarDeclarationReconciler(new QuickfixRegistry(), null);
5959
}
6060

61+
@Test
62+
void noValidationIfNoBeanRegistrar() throws Throwable {
63+
String source = """
64+
package com.example.demo;
65+
66+
import org.springframework.beans.factory.BeanRegistrar;
67+
import org.springframework.beans.factory.BeanRegistry;
68+
import org.springframework.core.env.Environment;
69+
70+
public class MyBeanRegistrar {
71+
72+
public void register(BeanRegistry registry, Environment env) {
73+
}
74+
75+
}
76+
""";
77+
List<ReconcileProblem> problems = reconcile(() -> {
78+
SpringMetamodelIndex springIndex = new SpringMetamodelIndex();
79+
80+
BeanRegistrarDeclarationReconciler r = new BeanRegistrarDeclarationReconciler(new QuickfixRegistry(), springIndex);
81+
82+
return r;
83+
}, "A.java", source, false);
84+
85+
assertEquals(0, problems.size());
86+
}
87+
6188
@Test
6289
void noConfigBeans() throws Throwable {
6390
String source = """

0 commit comments

Comments
 (0)