Skip to content

Commit

Permalink
GH-1041: removed outdated beans addon symbol information, now fully r…
Browse files Browse the repository at this point in the history
…eplaced with new spring index
  • Loading branch information
martinlippert committed Jan 10, 2025
1 parent 7c40f30 commit 435cd59
Show file tree
Hide file tree
Showing 13 changed files with 60 additions and 146 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import org.springframework.ide.vscode.boot.java.Annotations;
import org.springframework.ide.vscode.boot.java.handlers.AbstractSymbolProvider;
import org.springframework.ide.vscode.boot.java.handlers.EnhancedSymbolInformation;
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.FunctionUtils;
Expand Down Expand Up @@ -87,7 +86,7 @@ protected void addSymbolsPass1(Annotation node, ITypeBinding annotationType, Col
beanLabel(isFunction, nameAndRegion.getT1(), beanType.getName(), "@Bean" + markerString),
SymbolKind.Interface,
Either.forLeft(location)),
new SymbolAddOnInformation[] {new BeansSymbolAddOnInformation(nameAndRegion.getT1(), beanType.getQualifiedName())}
null
);

InjectionPoint[] injectionPoints = ASTUtils.findInjectionPoints(method, doc);
Expand Down Expand Up @@ -121,7 +120,7 @@ protected void addSymbolsPass1(TypeDeclaration typeDeclaration, SpringIndexerJav
Either.forLeft(new Location(doc.getUri(), doc.toRange(functionBean.getT3()))));

context.getGeneratedSymbols().add(new CachedSymbol(context.getDocURI(), context.getLastModified(),
new EnhancedSymbolInformation(symbol, new SymbolAddOnInformation[] {new BeansSymbolAddOnInformation(functionBean.getT1(), functionBean.getT2().getQualifiedName())})));
new EnhancedSymbolInformation(symbol, null)));

} catch (BadLocationException e) {
log.error("", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import org.springframework.ide.vscode.boot.java.Annotations;
import org.springframework.ide.vscode.boot.java.handlers.AbstractSymbolProvider;
import org.springframework.ide.vscode.boot.java.handlers.EnhancedSymbolInformation;
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;
Expand Down Expand Up @@ -93,8 +92,6 @@ protected Tuple.Two<EnhancedSymbolInformation, Bean> createSymbol(Annotation nod
boolean isConfiguration = Annotations.CONFIGURATION.equals(annotationType.getQualifiedName())
|| metaAnnotations.stream().anyMatch(t -> Annotations.CONFIGURATION.equals(t.getQualifiedName()));

SymbolAddOnInformation[] addon = new SymbolAddOnInformation[] {new BeansSymbolAddOnInformation(beanName, beanType.getQualifiedName())};

InjectionPoint[] injectionPoints = ASTUtils.findInjectionPoints(type, doc);

Set<String> supertypes = new HashSet<>();
Expand All @@ -111,7 +108,7 @@ protected Tuple.Two<EnhancedSymbolInformation, Bean> createSymbol(Annotation nod

Bean beanDefinition = new Bean(beanName, beanType.getQualifiedName(), location, injectionPoints, supertypes, annotations, isConfiguration);

return Tuple.two(new EnhancedSymbolInformation(symbol, addon), beanDefinition);
return Tuple.two(new EnhancedSymbolInformation(symbol, null), beanDefinition);
}

protected String beanLabel(String searchPrefix, String annotationTypeName, Collection<String> metaAnnotationNames, String beanName, String beanType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import org.slf4j.LoggerFactory;
import org.springframework.ide.vscode.boot.java.handlers.AbstractSymbolProvider;
import org.springframework.ide.vscode.boot.java.handlers.EnhancedSymbolInformation;
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.SpringIndexerJavaContext;
Expand Down Expand Up @@ -82,8 +81,6 @@ private Two<EnhancedSymbolInformation, Bean> createSymbol(Annotation node, IType
beanLabel("+", annotationTypeName, metaAnnotationNames, beanName, beanType == null ? "" : beanType.getName()), SymbolKind.Interface,
Either.forLeft(location));

SymbolAddOnInformation[] addon = new SymbolAddOnInformation[] {new BeansSymbolAddOnInformation(beanName, beanType == null ? "" : beanType.getQualifiedName())};

InjectionPoint[] injectionPoints = ASTUtils.findInjectionPoints(type, doc);

Set<String> supertypes = new HashSet<>();
Expand All @@ -100,7 +97,7 @@ private Two<EnhancedSymbolInformation, Bean> createSymbol(Annotation node, IType

Bean beanDefinition = new Bean(beanName, beanType == null ? "" : beanType.getQualifiedName(), location, injectionPoints, supertypes, annotations, false);

return Tuple.two(new EnhancedSymbolInformation(symbol, addon), beanDefinition);
return Tuple.two(new EnhancedSymbolInformation(symbol, null), beanDefinition);
}

protected String beanLabel(String searchPrefix, String annotationTypeName, Collection<String> metaAnnotationNames, String beanName, String beanType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,9 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ide.vscode.boot.java.beans.BeanUtils;
import org.springframework.ide.vscode.boot.java.beans.BeansSymbolAddOnInformation;
import org.springframework.ide.vscode.boot.java.beans.CachedBean;
import org.springframework.ide.vscode.boot.java.handlers.AbstractSymbolProvider;
import org.springframework.ide.vscode.boot.java.handlers.EnhancedSymbolInformation;
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.SpringIndexerJavaContext;
Expand Down Expand Up @@ -65,8 +63,7 @@ protected void addSymbolsPass1(TypeDeclaration typeDeclaration, SpringIndexerJav
SymbolKind.Interface,
Either.forLeft(location));

SymbolAddOnInformation[] addon = new SymbolAddOnInformation[] {new BeansSymbolAddOnInformation(repositoryBean.getT1(), repositoryBean.getT2().getQualifiedName())};
EnhancedSymbolInformation enhancedSymbol = new EnhancedSymbolInformation(symbol, addon);
EnhancedSymbolInformation enhancedSymbol = new EnhancedSymbolInformation(symbol, null);

InjectionPoint[] injectionPoints = ASTUtils.findInjectionPoints(typeDeclaration, doc);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,8 @@
import org.springframework.ide.vscode.boot.index.cache.IndexCache;
import org.springframework.ide.vscode.boot.index.cache.IndexCacheKey;
import org.springframework.ide.vscode.boot.java.beans.BeanUtils;
import org.springframework.ide.vscode.boot.java.beans.BeansSymbolAddOnInformation;
import org.springframework.ide.vscode.boot.java.beans.BeansSymbolProvider;
import org.springframework.ide.vscode.boot.java.handlers.EnhancedSymbolInformation;
import org.springframework.ide.vscode.boot.java.handlers.SymbolAddOnInformation;
import org.springframework.ide.vscode.commons.java.IClasspathUtil;
import org.springframework.ide.vscode.commons.java.IJavaProject;
import org.springframework.ide.vscode.commons.protocol.java.Classpath;
Expand Down Expand Up @@ -123,9 +121,7 @@ private List<EnhancedSymbolInformation> computeSymbols(String docURI, String con
symbols.add(new EnhancedSymbolInformation(new WorkspaceSymbol(
BeansSymbolProvider.beanLabel(false, beanId, fqName, Paths.get(URI.create(docURI)).getFileName().toString()),
SymbolKind.Interface,
Either.forLeft(new Location(docURI, range))), new SymbolAddOnInformation[] {
new BeansSymbolAddOnInformation(beanId, fqName)
}));
Either.forLeft(new Location(docURI, range))), null));
} catch (Exception e) {
log.error("", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public static enum SCAN_PASS {

// whenever the implementation of the indexer changes in a way that the stored data in the cache is no longer valid,
// we need to change the generation - this will result in a re-indexing due to no up-to-date cache data being found
private static final String GENERATION = "GEN-10";
private static final String GENERATION = "GEN-11";
private static final String INDEX_FILES_TASK_ID = "index-java-source-files-task-";

private static final String SYMBOL_KEY = "symbols";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,8 @@
import org.eclipse.lsp4j.WorkspaceSymbol;
import org.eclipse.lsp4j.jsonrpc.messages.Either;
import org.springframework.ide.vscode.boot.java.beans.BeanUtils;
import org.springframework.ide.vscode.boot.java.beans.BeansSymbolAddOnInformation;
import org.springframework.ide.vscode.boot.java.beans.CachedBean;
import org.springframework.ide.vscode.boot.java.handlers.EnhancedSymbolInformation;
import org.springframework.ide.vscode.boot.java.handlers.SymbolAddOnInformation;
import org.springframework.ide.vscode.commons.java.IJavaProject;
import org.springframework.ide.vscode.commons.protocol.spring.Bean;
import org.springframework.ide.vscode.commons.util.text.TextDocument;
Expand Down Expand Up @@ -94,9 +92,7 @@ else if (name != null && name.equals("class")) {
}

WorkspaceSymbol symbol = new WorkspaceSymbol("@+ '" + beanID + "' " + beanClass, SymbolKind.Interface, Either.forLeft(new Location(docURI, range)));
SymbolAddOnInformation[] addon = new SymbolAddOnInformation[] {new BeansSymbolAddOnInformation(beanID, fqBeanClass)};

EnhancedSymbolInformation fullSymbol = new EnhancedSymbolInformation(symbol, addon);
EnhancedSymbolInformation fullSymbol = new EnhancedSymbolInformation(symbol, null);

CachedSymbol cachedSymbol = new CachedSymbol(docURI, lastModified, fullSymbol);
generatedSymbols.add(cachedSymbol);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import static org.junit.jupiter.api.Assertions.assertEquals;

import java.io.File;
import java.util.List;
import java.util.Arrays;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;

Expand All @@ -26,9 +26,9 @@
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.java.beans.BeansSymbolAddOnInformation;
import org.springframework.ide.vscode.boot.java.handlers.SymbolAddOnInformation;
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;
Expand All @@ -43,9 +43,10 @@ public class SpringIndexerBeansTest {

@Autowired private BootLanguageServerHarness harness;
@Autowired private JavaProjectFinder projectFinder;
@Autowired private SpringSymbolIndex indexer;
@Autowired private SpringMetamodelIndex springIndex;

private File directory;
@Autowired private SpringSymbolIndex indexer;

@BeforeEach
public void setup() throws Exception {
Expand All @@ -69,19 +70,15 @@ void testScanSimpleConfigurationClass() throws Exception {
SpringIndexerHarness.symbol("@Configuration", "@+ 'simpleConfiguration' (@Configuration <: @Component) SimpleConfiguration"),
SpringIndexerHarness.symbol("@Bean", "@+ 'simpleBean' (@Bean) BeanClass")
);

List<? extends SymbolAddOnInformation> addon = indexer.getAdditonalInformation(docUri);
assertEquals(2, addon.size());

assertEquals(1, addon.stream()
.filter(info -> info instanceof BeansSymbolAddOnInformation)
.filter(info -> "simpleConfiguration".equals(((BeansSymbolAddOnInformation) info).getBeanID()))
.count());

assertEquals(1, addon.stream()
.filter(info -> info instanceof BeansSymbolAddOnInformation)
.filter(info -> "simpleBean".equals(((BeansSymbolAddOnInformation) info).getBeanID()))
.count());

Bean[] beans = springIndex.getBeansOfDocument(docUri);
assertEquals(2, beans.length);

Bean simpleConfigBean = Arrays.stream(beans).filter(bean -> bean.getName().equals("simpleConfiguration")).findFirst().get();
Bean simpleBean = Arrays.stream(beans).filter(bean -> bean.getName().equals("simpleBean")).findFirst().get();

assertEquals("org.test.SimpleConfiguration", simpleConfigBean.getType());
assertEquals("org.test.BeanClass", simpleBean.getType());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
*******************************************************************************/
package org.springframework.ide.vscode.boot.java.beans.test;

import static org.junit.jupiter.api.Assertions.assertEquals;

import java.io.File;
import java.util.List;
import java.util.Arrays;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;

import org.eclipse.lsp4j.TextDocumentIdentifier;

import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
Expand All @@ -26,9 +26,9 @@
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.java.beans.BeansSymbolAddOnInformation;
import org.springframework.ide.vscode.boot.java.handlers.SymbolAddOnInformation;
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;
Expand All @@ -44,6 +44,7 @@ public class SpringIndexerFunctionBeansTest {
@Autowired private BootLanguageServerHarness harness;
@Autowired private SpringSymbolIndex indexer;
@Autowired private JavaProjectFinder projectFinder;
@Autowired private SpringMetamodelIndex springIndex;

private File directory;

Expand All @@ -70,18 +71,14 @@ void testScanSimpleFunctionBean() throws Exception {
SpringIndexerHarness.symbol("@Bean", "@> 'uppercase' (@Bean) Function<String,String>")
);

List<? extends SymbolAddOnInformation> addon = indexer.getAdditonalInformation(docUri);
assertEquals(2, addon.size());

assertEquals(1, addon.stream()
.filter(info -> info instanceof BeansSymbolAddOnInformation)
.filter(info -> "functionClass".equals(((BeansSymbolAddOnInformation) info).getBeanID()))
.count());

assertEquals(1, addon.stream()
.filter(info -> info instanceof BeansSymbolAddOnInformation)
.filter(info -> "uppercase".equals(((BeansSymbolAddOnInformation) info).getBeanID()))
.count());
Bean[] beans = springIndex.getBeansOfDocument(docUri);
assertEquals(2, beans.length);

Bean configBean = Arrays.stream(beans).filter(bean -> bean.getName().equals("functionClass")).findFirst().get();
Bean functionBean = Arrays.stream(beans).filter(bean -> bean.getName().equals("uppercase")).findFirst().get();

assertEquals("org.test.FunctionClass", configBean.getType());
assertEquals("java.util.function.Function<java.lang.String,java.lang.String>", functionBean.getType());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2018, 2019 Pivotal, Inc.
* Copyright (c) 2018, 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
Expand All @@ -19,6 +19,7 @@
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;

import org.apache.commons.lang3.ArrayUtils;
import org.eclipse.lsp4j.TextDocumentIdentifier;
import org.eclipse.lsp4j.WorkspaceSymbol;
import org.junit.jupiter.api.BeforeEach;
Expand All @@ -29,9 +30,9 @@
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.java.beans.BeansSymbolAddOnInformation;
import org.springframework.ide.vscode.boot.java.handlers.SymbolAddOnInformation;
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;
Expand All @@ -47,6 +48,7 @@ public class DataRepositorySymbolProviderTest {
@Autowired private BootLanguageServerHarness harness;
@Autowired private JavaProjectFinder projectFinder;
@Autowired private SpringSymbolIndex indexer;
@Autowired private SpringMetamodelIndex springIndex;

private File directory;

Expand All @@ -71,10 +73,14 @@ void testSimpleRepositorySymbol() throws Exception {
assertEquals(1, symbols.size());
assertTrue(containsSymbol(symbols, "@+ 'customerRepository' (Customer) Repository<Customer,Long>", docUri, 6, 17, 6, 35));

List<? extends SymbolAddOnInformation> addon = indexer.getAdditonalInformation(docUri);
assertEquals(1, addon.size());

assertEquals("customerRepository", ((BeansSymbolAddOnInformation) addon.get(0)).getBeanID());
Bean[] repoBean = this.springIndex.getBeansWithName("test-spring-data-symbols", "customerRepository");
assertEquals(1, repoBean.length);
assertEquals("customerRepository", repoBean[0].getName());
assertEquals("org.test.CustomerRepository", repoBean[0].getType());

Bean[] matchingBeans = springIndex.getMatchingBeans("test-spring-data-symbols", "org.springframework.data.repository.CrudRepository");
assertEquals(2, matchingBeans.length);
ArrayUtils.contains(matchingBeans, repoBean[0]);
}

private boolean containsSymbol(List<? extends WorkspaceSymbol> symbols, String name, String uri, int startLine, int startCHaracter, int endLine, int endCharacter) {
Expand Down
Loading

0 comments on commit 435cd59

Please sign in to comment.