Skip to content

Commit c1b1a06

Browse files
committed
GH-1043: create correct bean index element for functional beans that implement the function interface
Fixes GH-1043
1 parent f58305d commit c1b1a06

File tree

2 files changed

+46
-2
lines changed

2 files changed

+46
-2
lines changed

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

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,31 @@ protected void addSymbolsPass1(TypeDeclaration typeDeclaration, SpringIndexerJav
114114
Tuple3<String, ITypeBinding, DocumentRegion> functionBean = FunctionUtils.getFunctionBean(typeDeclaration, doc);
115115
if (functionBean != null) {
116116
try {
117+
String beanName = functionBean.getT1();
118+
ITypeBinding beanType = functionBean.getT2();
119+
Location beanLocation = new Location(doc.getUri(), doc.toRange(functionBean.getT3()));
120+
117121
WorkspaceSymbol symbol = new WorkspaceSymbol(
118-
beanLabel(true, functionBean.getT1(), functionBean.getT2().getName(), null),
122+
beanLabel(true, beanName, beanType.getName(), null),
119123
SymbolKind.Interface,
120-
Either.forLeft(new Location(doc.getUri(), doc.toRange(functionBean.getT3()))));
124+
Either.forLeft(beanLocation));
121125

122126
context.getGeneratedSymbols().add(new CachedSymbol(context.getDocURI(), context.getLastModified(),
123127
new EnhancedSymbolInformation(symbol, null)));
124128

129+
130+
ITypeBinding concreteBeanType = typeDeclaration.resolveBinding();
131+
Set<String> supertypes = new HashSet<>();
132+
ASTUtils.findSupertypes(concreteBeanType, supertypes);
133+
134+
Collection<Annotation> annotationsOnTypeDeclaration = ASTUtils.getAnnotations(typeDeclaration);
135+
AnnotationMetadata[] annotations = ASTUtils.getAnnotationsMetadata(annotationsOnTypeDeclaration, doc);
136+
137+
InjectionPoint[] injectionPoints = ASTUtils.findInjectionPoints(typeDeclaration, doc);
138+
139+
Bean beanDefinition = new Bean(beanName, concreteBeanType.getQualifiedName(), beanLocation, injectionPoints, supertypes, annotations, false);
140+
context.getBeans().add(new CachedBean(context.getDocURI(), beanDefinition));
141+
125142
} catch (BadLocationException e) {
126143
log.error("", e);
127144
}

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,13 @@ void testScanSimpleFunctionClass() throws Exception {
8787
SpringIndexerHarness.assertDocumentSymbols(indexer, docUri,
8888
SpringIndexerHarness.symbol("ScannedFunctionClass", "@> 'scannedFunctionClass' Function<String,String>")
8989
);
90+
91+
Bean[] beans = springIndex.getBeansOfDocument(docUri);
92+
assertEquals(1, beans.length);
93+
94+
Bean functionClassBean = Arrays.stream(beans).filter(bean -> bean.getName().equals("scannedFunctionClass")).findFirst().get();
95+
96+
assertEquals("org.test.ScannedFunctionClass", functionClassBean.getType());
9097
}
9198

9299
@Test
@@ -95,6 +102,13 @@ void testScanSpecializedFunctionClass() throws Exception {
95102
SpringIndexerHarness.assertDocumentSymbols(indexer, docUri,
96103
SpringIndexerHarness.symbol("FunctionFromSpecializedClass", "@> 'functionFromSpecializedClass' Function<String,String>")
97104
);
105+
106+
Bean[] beans = springIndex.getBeansOfDocument(docUri);
107+
assertEquals(1, beans.length);
108+
109+
Bean functionClassBean = Arrays.stream(beans).filter(bean -> bean.getName().equals("functionFromSpecializedClass")).findFirst().get();
110+
111+
assertEquals("org.test.FunctionFromSpecializedClass", functionClassBean.getType());
98112
}
99113

100114
@Test
@@ -103,18 +117,31 @@ void testScanSpecializedFunctionInterface() throws Exception {
103117
SpringIndexerHarness.assertDocumentSymbols(indexer, docUri,
104118
SpringIndexerHarness.symbol("FunctionFromSpecializedInterface", "@> 'functionFromSpecializedInterface' Function<String,String>")
105119
);
120+
121+
Bean[] beans = springIndex.getBeansOfDocument(docUri);
122+
assertEquals(1, beans.length);
123+
124+
Bean functionClassBean = Arrays.stream(beans).filter(bean -> bean.getName().equals("functionFromSpecializedInterface")).findFirst().get();
125+
126+
assertEquals("org.test.FunctionFromSpecializedInterface", functionClassBean.getType());
106127
}
107128

108129
@Test
109130
void testNoSymbolForAbstractClasses() throws Exception {
110131
String docUri = directory.toPath().resolve("src/main/java/org/test/SpecializedFunctionClass.java").toUri().toString();
111132
SpringIndexerHarness.assertDocumentSymbols(indexer, docUri);
133+
134+
Bean[] beans = springIndex.getBeansOfDocument(docUri);
135+
assertEquals(0, beans.length);
112136
}
113137

114138
@Test
115139
void testNoSymbolForSubInterfaces() throws Exception {
116140
String docUri = directory.toPath().resolve("src/main/java/org/test/SpecializedFunctionInterface.java").toUri().toString();
117141
SpringIndexerHarness.assertDocumentSymbols(indexer, docUri);
142+
143+
Bean[] beans = springIndex.getBeansOfDocument(docUri);
144+
assertEquals(0, beans.length);
118145
}
119146

120147
}

0 commit comments

Comments
 (0)