GH-1043: create correct bean index element for functional beans that implement the function interface
Fixes GH-1043
This commit is contained in:
@@ -114,14 +114,31 @@ public class BeansSymbolProvider extends AbstractSymbolProvider {
|
||||
Tuple3<String, ITypeBinding, DocumentRegion> functionBean = FunctionUtils.getFunctionBean(typeDeclaration, doc);
|
||||
if (functionBean != null) {
|
||||
try {
|
||||
String beanName = functionBean.getT1();
|
||||
ITypeBinding beanType = functionBean.getT2();
|
||||
Location beanLocation = new Location(doc.getUri(), doc.toRange(functionBean.getT3()));
|
||||
|
||||
WorkspaceSymbol symbol = new WorkspaceSymbol(
|
||||
beanLabel(true, functionBean.getT1(), functionBean.getT2().getName(), null),
|
||||
beanLabel(true, beanName, beanType.getName(), null),
|
||||
SymbolKind.Interface,
|
||||
Either.forLeft(new Location(doc.getUri(), doc.toRange(functionBean.getT3()))));
|
||||
Either.forLeft(beanLocation));
|
||||
|
||||
context.getGeneratedSymbols().add(new CachedSymbol(context.getDocURI(), context.getLastModified(),
|
||||
new EnhancedSymbolInformation(symbol, null)));
|
||||
|
||||
|
||||
ITypeBinding concreteBeanType = typeDeclaration.resolveBinding();
|
||||
Set<String> supertypes = new HashSet<>();
|
||||
ASTUtils.findSupertypes(concreteBeanType, supertypes);
|
||||
|
||||
Collection<Annotation> annotationsOnTypeDeclaration = ASTUtils.getAnnotations(typeDeclaration);
|
||||
AnnotationMetadata[] annotations = ASTUtils.getAnnotationsMetadata(annotationsOnTypeDeclaration, doc);
|
||||
|
||||
InjectionPoint[] injectionPoints = ASTUtils.findInjectionPoints(typeDeclaration, doc);
|
||||
|
||||
Bean beanDefinition = new Bean(beanName, concreteBeanType.getQualifiedName(), beanLocation, injectionPoints, supertypes, annotations, false);
|
||||
context.getBeans().add(new CachedBean(context.getDocURI(), beanDefinition));
|
||||
|
||||
} catch (BadLocationException e) {
|
||||
log.error("", e);
|
||||
}
|
||||
|
||||
@@ -87,6 +87,13 @@ public class SpringIndexerFunctionBeansTest {
|
||||
SpringIndexerHarness.assertDocumentSymbols(indexer, docUri,
|
||||
SpringIndexerHarness.symbol("ScannedFunctionClass", "@> 'scannedFunctionClass' Function<String,String>")
|
||||
);
|
||||
|
||||
Bean[] beans = springIndex.getBeansOfDocument(docUri);
|
||||
assertEquals(1, beans.length);
|
||||
|
||||
Bean functionClassBean = Arrays.stream(beans).filter(bean -> bean.getName().equals("scannedFunctionClass")).findFirst().get();
|
||||
|
||||
assertEquals("org.test.ScannedFunctionClass", functionClassBean.getType());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -95,6 +102,13 @@ public class SpringIndexerFunctionBeansTest {
|
||||
SpringIndexerHarness.assertDocumentSymbols(indexer, docUri,
|
||||
SpringIndexerHarness.symbol("FunctionFromSpecializedClass", "@> 'functionFromSpecializedClass' Function<String,String>")
|
||||
);
|
||||
|
||||
Bean[] beans = springIndex.getBeansOfDocument(docUri);
|
||||
assertEquals(1, beans.length);
|
||||
|
||||
Bean functionClassBean = Arrays.stream(beans).filter(bean -> bean.getName().equals("functionFromSpecializedClass")).findFirst().get();
|
||||
|
||||
assertEquals("org.test.FunctionFromSpecializedClass", functionClassBean.getType());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -103,18 +117,31 @@ public class SpringIndexerFunctionBeansTest {
|
||||
SpringIndexerHarness.assertDocumentSymbols(indexer, docUri,
|
||||
SpringIndexerHarness.symbol("FunctionFromSpecializedInterface", "@> 'functionFromSpecializedInterface' Function<String,String>")
|
||||
);
|
||||
|
||||
Bean[] beans = springIndex.getBeansOfDocument(docUri);
|
||||
assertEquals(1, beans.length);
|
||||
|
||||
Bean functionClassBean = Arrays.stream(beans).filter(bean -> bean.getName().equals("functionFromSpecializedInterface")).findFirst().get();
|
||||
|
||||
assertEquals("org.test.FunctionFromSpecializedInterface", functionClassBean.getType());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testNoSymbolForAbstractClasses() throws Exception {
|
||||
String docUri = directory.toPath().resolve("src/main/java/org/test/SpecializedFunctionClass.java").toUri().toString();
|
||||
SpringIndexerHarness.assertDocumentSymbols(indexer, docUri);
|
||||
|
||||
Bean[] beans = springIndex.getBeansOfDocument(docUri);
|
||||
assertEquals(0, beans.length);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testNoSymbolForSubInterfaces() throws Exception {
|
||||
String docUri = directory.toPath().resolve("src/main/java/org/test/SpecializedFunctionInterface.java").toUri().toString();
|
||||
SpringIndexerHarness.assertDocumentSymbols(indexer, docUri);
|
||||
|
||||
Bean[] beans = springIndex.getBeansOfDocument(docUri);
|
||||
assertEquals(0, beans.length);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user