GH-1313: symbol support for named annotation
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2019 Pivotal, Inc.
|
||||
* Copyright (c) 2019, 2024 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
@@ -47,6 +47,8 @@ public class SpringSymbolIndexerConfig {
|
||||
|
||||
providers.put(Annotations.BEAN, beansSymbolProvider);
|
||||
providers.put(Annotations.COMPONENT, componentSymbolProvider);
|
||||
providers.put(Annotations.NAMED_JAKARTA, componentSymbolProvider);
|
||||
providers.put(Annotations.NAMED_JAVAX, componentSymbolProvider);
|
||||
|
||||
providers.put(Annotations.PROFILE, restrictedDefaultSymbolProvider);
|
||||
|
||||
|
||||
@@ -33,6 +33,7 @@ import org.springframework.ide.vscode.boot.java.handlers.EnhancedSymbolInformati
|
||||
import org.springframework.ide.vscode.boot.java.handlers.SymbolAddOnInformation;
|
||||
import org.springframework.ide.vscode.boot.java.utils.ASTUtils;
|
||||
import org.springframework.ide.vscode.boot.java.utils.CachedSymbol;
|
||||
import org.springframework.ide.vscode.boot.java.utils.DefaultSymbolProvider;
|
||||
import org.springframework.ide.vscode.boot.java.utils.SpringIndexerJavaContext;
|
||||
import org.springframework.ide.vscode.commons.protocol.spring.AnnotationMetadata;
|
||||
import org.springframework.ide.vscode.commons.protocol.spring.Bean;
|
||||
@@ -47,6 +48,7 @@ import org.springframework.ide.vscode.commons.util.text.TextDocument;
|
||||
public class ComponentSymbolProvider extends AbstractSymbolProvider {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(ComponentSymbolProvider.class);
|
||||
private static final Set<String> NAMED_ANNOTATIONS = Set.of(Annotations.NAMED_JAKARTA, Annotations.NAMED_JAVAX);
|
||||
|
||||
@Override
|
||||
protected void addSymbolsPass1(Annotation node, ITypeBinding annotationType, Collection<ITypeBinding> metaAnnotations, SpringIndexerJavaContext context, TextDocument doc) {
|
||||
@@ -59,6 +61,11 @@ public class ComponentSymbolProvider extends AbstractSymbolProvider {
|
||||
context.getGeneratedSymbols().add(new CachedSymbol(context.getDocURI(), context.getLastModified(), enhancedSymbol));
|
||||
context.getBeans().add(new CachedBean(context.getDocURI(), beanDefinition));
|
||||
}
|
||||
else if (NAMED_ANNOTATIONS.contains(annotationType.getQualifiedName())) {
|
||||
WorkspaceSymbol symbol = DefaultSymbolProvider.provideDefaultSymbol(node, doc);
|
||||
EnhancedSymbolInformation enhancedSymbol = new EnhancedSymbolInformation(symbol, null);
|
||||
context.getGeneratedSymbols().add(new CachedSymbol(context.getDocURI(), context.getLastModified(), enhancedSymbol));
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
log.error("", e);
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.boot.java.beans.test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@@ -23,7 +25,9 @@ import org.springframework.context.annotation.Import;
|
||||
import org.springframework.ide.vscode.boot.app.SpringSymbolIndex;
|
||||
import org.springframework.ide.vscode.boot.bootiful.BootLanguageServerTest;
|
||||
import org.springframework.ide.vscode.boot.bootiful.SymbolProviderTestConf;
|
||||
import org.springframework.ide.vscode.boot.index.SpringMetamodelIndex;
|
||||
import org.springframework.ide.vscode.commons.languageserver.java.JavaProjectFinder;
|
||||
import org.springframework.ide.vscode.commons.protocol.spring.Bean;
|
||||
import org.springframework.ide.vscode.project.harness.BootLanguageServerHarness;
|
||||
import org.springframework.ide.vscode.project.harness.ProjectsHarness;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
@@ -38,9 +42,10 @@ public class SpringIndexerJakartaJavaxAnnotationsTest {
|
||||
|
||||
@Autowired private BootLanguageServerHarness harness;
|
||||
@Autowired private JavaProjectFinder projectFinder;
|
||||
@Autowired private SpringMetamodelIndex springIndex;
|
||||
@Autowired private SpringSymbolIndex indexer;
|
||||
|
||||
private File directory;
|
||||
@Autowired private SpringSymbolIndex indexer;
|
||||
|
||||
@BeforeEach
|
||||
public void setup() throws Exception {
|
||||
@@ -68,7 +73,36 @@ public class SpringIndexerJakartaJavaxAnnotationsTest {
|
||||
SpringIndexerHarness.symbol("@Inject", "@Inject"),
|
||||
SpringIndexerHarness.symbol("@Named(\"specificFinder\")", "@Named(\"specificFinder\")")
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testNamedAnnotationJakarta() throws Exception {
|
||||
String docUri = directory.toPath().resolve("src/main/java/org/test/jakarta/NamedComponentWithSpecificName.java").toUri().toString();
|
||||
|
||||
SpringIndexerHarness.assertDocumentSymbols(indexer, docUri,
|
||||
SpringIndexerHarness.symbol("@Named(\"specificallyNamedComponent\")", "@+ 'namedComponentWithSpecificName' (@Named) NamedComponentWithSpecificName")
|
||||
);
|
||||
|
||||
Bean[] beans = springIndex.getBeansOfDocument(docUri);
|
||||
assertEquals(1, beans.length);
|
||||
|
||||
assertEquals("namedComponentWithSpecificName", beans[0].getName());
|
||||
assertEquals("org.test.jakarta.NamedComponentWithSpecificName", beans[0].getType());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testNamedAnnotationJavax() throws Exception {
|
||||
String docUri = directory.toPath().resolve("src/main/java/org/test/javax/NamedComponentWithSpecificName.java").toUri().toString();
|
||||
|
||||
SpringIndexerHarness.assertDocumentSymbols(indexer, docUri,
|
||||
SpringIndexerHarness.symbol("@Named(\"specificallyNamedComponent\")", "@+ 'namedComponentWithSpecificName' (@Named) NamedComponentWithSpecificName")
|
||||
);
|
||||
|
||||
Bean[] beans = springIndex.getBeansOfDocument(docUri);
|
||||
assertEquals(1, beans.length);
|
||||
|
||||
assertEquals("namedComponentWithSpecificName", beans[0].getName());
|
||||
assertEquals("org.test.javax.NamedComponentWithSpecificName", beans[0].getType());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user