GH-1041: removed enhanced bean symbol wrapper class as a final step

Fixes GH-1041
This commit is contained in:
Martin Lippert
2025-02-07 09:44:46 +01:00
parent b3c7e7f560
commit 6698801ed4
20 changed files with 173 additions and 300 deletions

View File

@@ -38,7 +38,6 @@ import java.util.concurrent.atomic.AtomicReference;
import java.util.function.BiConsumer;
import java.util.function.BiFunction;
import java.util.function.Consumer;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@@ -56,7 +55,6 @@ import org.springframework.ide.vscode.boot.index.SpringMetamodelIndex;
import org.springframework.ide.vscode.boot.index.cache.IndexCache;
import org.springframework.ide.vscode.boot.java.BootJavaLanguageServerComponents;
import org.springframework.ide.vscode.boot.java.annotations.AnnotationHierarchyAwareLookup;
import org.springframework.ide.vscode.boot.java.handlers.EnhancedSymbolInformation;
import org.springframework.ide.vscode.boot.java.handlers.SymbolProvider;
import org.springframework.ide.vscode.boot.java.reconcilers.JdtReconciler;
import org.springframework.ide.vscode.boot.java.utils.CompilationUnitCache;
@@ -111,10 +109,10 @@ public class SpringSymbolIndex implements InitializingBean, SpringIndex {
private static final String QUERY_PARAM_LOCATION_PREFIX = "locationPrefix:";
private final List<EnhancedSymbolInformation> symbols = new ArrayList<>();
private final List<WorkspaceSymbol> symbols = new ArrayList<>();
private final ConcurrentMap<String, List<EnhancedSymbolInformation>> symbolsByDoc = new ConcurrentHashMap<>();
private final ConcurrentMap<String, List<EnhancedSymbolInformation>> symbolsByProject = new ConcurrentHashMap<>();
private final ConcurrentMap<String, List<WorkspaceSymbol>> symbolsByDoc = new ConcurrentHashMap<>();
private final ConcurrentMap<String, List<WorkspaceSymbol>> symbolsByProject = new ConcurrentHashMap<>();
private final ExecutorService updateQueue = Executors.newSingleThreadExecutor();
private final Map<String, CompletableFuture<Void>> latestScheduledTaskByProject = new ConcurrentHashMap<String, CompletableFuture<Void>>();
@@ -168,7 +166,7 @@ public class SpringSymbolIndex implements InitializingBean, SpringIndex {
SymbolHandler handler = new SymbolHandler() {
@Override
public void addSymbols(IJavaProject project, String docURI, EnhancedSymbolInformation[] enhancedSymbols, List<SpringIndexElement> beanDefinitions,
public void addSymbols(IJavaProject project, String docURI, WorkspaceSymbol[] enhancedSymbols, List<SpringIndexElement> beanDefinitions,
List<Diagnostic> diagnostics) {
if (enhancedSymbols != null) {
@@ -186,26 +184,26 @@ public class SpringSymbolIndex implements InitializingBean, SpringIndex {
}
@Override
public void addSymbols(IJavaProject project, EnhancedSymbolInformation[] enhancedSymbols,
public void addSymbols(IJavaProject project, WorkspaceSymbol[] enhancedSymbols,
Map<String, List<SpringIndexElement>> beanDefinitionsByDoc, Map<String, List<Diagnostic>> diagnosticsPerDoc) {
if (enhancedSymbols != null) {
// organize symbols by doc URI
Map<String, List<EnhancedSymbolInformation>> symbolsPerDoc = new HashMap<>();
for (EnhancedSymbolInformation symbol : enhancedSymbols) {
Either<Location, WorkspaceSymbolLocation> location = symbol.getSymbol().getLocation();
Map<String, List<WorkspaceSymbol>> symbolsPerDoc = new HashMap<>();
for (WorkspaceSymbol symbol : enhancedSymbols) {
Either<Location, WorkspaceSymbolLocation> location = symbol.getLocation();
String docURI = location.isLeft() ? location.getLeft().getUri() : location.getRight().getUri();
symbolsPerDoc.computeIfAbsent(docURI, k -> new ArrayList<>()).add(symbol);
}
// add symbols per doc
for (Map.Entry<String, List<EnhancedSymbolInformation>> entry : symbolsPerDoc.entrySet()) {
for (Map.Entry<String, List<WorkspaceSymbol>> entry : symbolsPerDoc.entrySet()) {
String docURI = entry.getKey();
List<EnhancedSymbolInformation> symbols = entry.getValue();
List<WorkspaceSymbol> symbols = entry.getValue();
SpringSymbolIndex.this.addSymbolsByDoc(project, docURI, (EnhancedSymbolInformation[]) symbols.toArray(new EnhancedSymbolInformation[symbols.size()]));
SpringSymbolIndex.this.addSymbolsByDoc(project, docURI, (WorkspaceSymbol[]) symbols.toArray(new WorkspaceSymbol[symbols.size()]));
}
}
@@ -596,13 +594,13 @@ public class SpringSymbolIndex implements InitializingBean, SpringIndex {
}
private Collection<? extends String> getDocsFromPath(IJavaProject project, String path) {
List<EnhancedSymbolInformation> allProjectSymbols = this.symbolsByProject.get(project.getElementName());
List<WorkspaceSymbol> allProjectSymbols = this.symbolsByProject.get(project.getElementName());
Set<String> result = new HashSet<>();
if (allProjectSymbols != null) {
for (EnhancedSymbolInformation symbol : allProjectSymbols) {
Either<Location, WorkspaceSymbolLocation> location = symbol.getSymbol().getLocation();
for (WorkspaceSymbol symbol : allProjectSymbols) {
Either<Location, WorkspaceSymbolLocation> location = symbol.getLocation();
String docURI = null;
if (location.isLeft()) {
@@ -680,22 +678,11 @@ public class SpringSymbolIndex implements InitializingBean, SpringIndex {
}
} else {
synchronized(this.symbols) {
return this.symbols.stream().map(s -> s.getSymbol()).collect(Collectors.toList());
return this.symbols.stream().collect(Collectors.toList());
}
}
}
public Stream<WorkspaceSymbol> getSymbols(Predicate<EnhancedSymbolInformation> filter) {
return symbols.stream()
.filter(filter)
.map(enhanced -> enhanced.getSymbol());
}
public List<EnhancedSymbolInformation> getEnhancedSymbols(IJavaProject project) {
List<EnhancedSymbolInformation> list = symbolsByProject.get(project.getElementName());
return list == null ? Collections.emptyList() : Collections.unmodifiableList(list);
}
synchronized private CompletableFuture<IJavaProject> projectInitializedFuture(IJavaProject project) {
if (project == null) {
return CompletableFuture.completedFuture(null);
@@ -718,9 +705,9 @@ public class SpringSymbolIndex implements InitializingBean, SpringIndex {
for (SpringIndexer indexer : this.indexers) {
if (indexer.isInterestedIn(docURI)) {
try {
for (EnhancedSymbolInformation enhanced : indexer.computeSymbols(project, docURI,
for (WorkspaceSymbol enhanced : indexer.computeSymbols(project, docURI,
doc.get())) {
builder.add(enhanced.getSymbol());
builder.add(enhanced);
}
} catch (Exception e) {
log.error("{}", e);
@@ -730,11 +717,11 @@ public class SpringSymbolIndex implements InitializingBean, SpringIndex {
}
} else {
// Take symbols from the index if there is no opened document.
List<EnhancedSymbolInformation> docSymbols = this.symbolsByDoc.get(uri.toASCIIString());
List<WorkspaceSymbol> docSymbols = this.symbolsByDoc.get(uri.toASCIIString());
if (docSymbols != null) {
synchronized (docSymbols) {
for (EnhancedSymbolInformation enhanced : docSymbols) {
builder.add(enhanced.getSymbol());
for (WorkspaceSymbol symbol : docSymbols) {
builder.add(symbol);
}
}
}
@@ -793,7 +780,7 @@ public class SpringSymbolIndex implements InitializingBean, SpringIndex {
}, this.updateQueue);
}
private List<WorkspaceSymbol> searchMatchingSymbols(List<EnhancedSymbolInformation> allsymbols, String query) {
private List<WorkspaceSymbol> searchMatchingSymbols(List<WorkspaceSymbol> allsymbols, String query) {
String locationPrefix = "";
if (query.startsWith(QUERY_PARAM_LOCATION_PREFIX)) {
@@ -817,7 +804,6 @@ public class SpringSymbolIndex implements InitializingBean, SpringIndex {
String finalLocationPrefix = locationPrefix;
return allsymbols.stream()
.map(enhanced -> enhanced.getSymbol())
.filter(symbol -> {
Either<Location, WorkspaceSymbolLocation> eitherLocation = symbol.getLocation();
if (eitherLocation.isLeft()) {
@@ -964,12 +950,12 @@ public class SpringSymbolIndex implements InitializingBean, SpringIndex {
}
private void addSymbolsByDoc(IJavaProject project, String docURI, EnhancedSymbolInformation[] enhancedSymbols) {
private void addSymbolsByDoc(IJavaProject project, String docURI, WorkspaceSymbol[] enhancedSymbols) {
List<EnhancedSymbolInformation> docSymbols = symbolsByDoc.computeIfAbsent(docURI, s -> new ArrayList<EnhancedSymbolInformation>());
List<EnhancedSymbolInformation> projectSymbols = symbolsByProject.computeIfAbsent(project.getElementName(), s -> new ArrayList<EnhancedSymbolInformation>());
List<WorkspaceSymbol> docSymbols = symbolsByDoc.computeIfAbsent(docURI, s -> new ArrayList<WorkspaceSymbol>());
List<WorkspaceSymbol> projectSymbols = symbolsByProject.computeIfAbsent(project.getElementName(), s -> new ArrayList<WorkspaceSymbol>());
for (EnhancedSymbolInformation enhancedSymbol : enhancedSymbols) {
for (WorkspaceSymbol enhancedSymbol : enhancedSymbols) {
synchronized(this.symbols) {
symbols.add(enhancedSymbol);
@@ -988,10 +974,10 @@ public class SpringSymbolIndex implements InitializingBean, SpringIndex {
}
private void removeSymbolsByDoc(IJavaProject project, String docURI) {
List<EnhancedSymbolInformation> oldSymbols = symbolsByDoc.remove(docURI);
List<WorkspaceSymbol> oldSymbols = symbolsByDoc.remove(docURI);
if (oldSymbols != null) {
List<EnhancedSymbolInformation> copy = null;
List<WorkspaceSymbol> copy = null;
synchronized(oldSymbols) {
copy = new ArrayList<>(oldSymbols);
}
@@ -1000,7 +986,7 @@ public class SpringSymbolIndex implements InitializingBean, SpringIndex {
this.symbols.removeAll(copy);
}
List<EnhancedSymbolInformation> projectSymbols = symbolsByProject.get(project.getElementName());
List<WorkspaceSymbol> projectSymbols = symbolsByProject.get(project.getElementName());
if (projectSymbols != null) {
synchronized(projectSymbols) {
projectSymbols.removeAll(copy);
@@ -1014,10 +1000,10 @@ public class SpringSymbolIndex implements InitializingBean, SpringIndex {
if (project.getElementName() == null) {
return;
}
List<EnhancedSymbolInformation> oldSymbols = symbolsByProject.remove(project.getElementName());
List<WorkspaceSymbol> oldSymbols = symbolsByProject.remove(project.getElementName());
if (oldSymbols != null) {
List<EnhancedSymbolInformation> copy = null;
List<WorkspaceSymbol> copy = null;
synchronized(oldSymbols) {
copy = new ArrayList<>(oldSymbols);
}
@@ -1030,7 +1016,7 @@ public class SpringSymbolIndex implements InitializingBean, SpringIndex {
Iterator<String> docIter = keySet.iterator();
while (docIter.hasNext()) {
String docURI = docIter.next();
List<EnhancedSymbolInformation> docSymbols = symbolsByDoc.get(docURI);
List<WorkspaceSymbol> docSymbols = symbolsByDoc.get(docURI);
synchronized(docSymbols) {
docSymbols.removeAll(copy);

View File

@@ -34,7 +34,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
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.requestmapping.WebfluxRouterSymbolProvider;
import org.springframework.ide.vscode.boot.java.utils.ASTUtils;
import org.springframework.ide.vscode.boot.java.utils.CachedSymbol;
@@ -95,11 +94,10 @@ public class BeansSymbolProvider extends AbstractSymbolProvider {
try {
Location location = new Location(doc.getUri(), doc.toRange(nameAndRegion.getT2()));
EnhancedSymbolInformation enhancedSymbol = new EnhancedSymbolInformation(
new WorkspaceSymbol(
WorkspaceSymbol symbol = new WorkspaceSymbol(
beanLabel(isFunction, nameAndRegion.getT1(), beanType.getName(), "@Bean" + markerString),
SymbolKind.Interface,
Either.forLeft(location))
Either.forLeft(location)
);
InjectionPoint[] injectionPoints = ASTUtils.findInjectionPoints(method, doc);
@@ -117,7 +115,7 @@ public class BeansSymbolProvider extends AbstractSymbolProvider {
}
}
context.getGeneratedSymbols().add(new CachedSymbol(context.getDocURI(), context.getLastModified(), enhancedSymbol));
context.getGeneratedSymbols().add(new CachedSymbol(context.getDocURI(), context.getLastModified(), symbol));
context.getBeans().add(new CachedBean(context.getDocURI(), beanDefinition));
} catch (BadLocationException e) {
@@ -141,9 +139,7 @@ public class BeansSymbolProvider extends AbstractSymbolProvider {
SymbolKind.Interface,
Either.forLeft(beanLocation));
context.getGeneratedSymbols().add(new CachedSymbol(context.getDocURI(), context.getLastModified(),
new EnhancedSymbolInformation(symbol)));
context.getGeneratedSymbols().add(new CachedSymbol(context.getDocURI(), context.getLastModified(), symbol));
ITypeBinding concreteBeanType = typeDeclaration.resolveBinding();
Set<String> supertypes = new HashSet<>();

View File

@@ -37,7 +37,6 @@ import org.springframework.ide.vscode.boot.java.Annotations;
import org.springframework.ide.vscode.boot.java.events.EventListenerIndexElement;
import org.springframework.ide.vscode.boot.java.events.EventPublisherIndexElement;
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.utils.ASTUtils;
import org.springframework.ide.vscode.boot.java.utils.CachedSymbol;
import org.springframework.ide.vscode.boot.java.utils.DefaultSymbolProvider;
@@ -65,8 +64,7 @@ public class ComponentSymbolProvider extends AbstractSymbolProvider {
}
else if (Annotations.NAMED_ANNOTATIONS.contains(annotationType.getQualifiedName())) {
WorkspaceSymbol symbol = DefaultSymbolProvider.provideDefaultSymbol(node, doc);
EnhancedSymbolInformation enhancedSymbol = new EnhancedSymbolInformation(symbol);
context.getGeneratedSymbols().add(new CachedSymbol(context.getDocURI(), context.getLastModified(), enhancedSymbol));
context.getGeneratedSymbols().add(new CachedSymbol(context.getDocURI(), context.getLastModified(), symbol));
}
}
catch (Exception e) {
@@ -129,7 +127,7 @@ public class ComponentSymbolProvider extends AbstractSymbolProvider {
}
}
context.getGeneratedSymbols().add(new CachedSymbol(context.getDocURI(), context.getLastModified(), new EnhancedSymbolInformation(symbol)));
context.getGeneratedSymbols().add(new CachedSymbol(context.getDocURI(), context.getLastModified(), symbol));
context.getBeans().add(new CachedBean(context.getDocURI(), beanDefinition));
}
@@ -169,8 +167,7 @@ public class ComponentSymbolProvider extends AbstractSymbolProvider {
// symbol
String symbolLabel = "@EventPublisher (" + eventTypeBinding.getName() + ")";
WorkspaceSymbol symbol = new WorkspaceSymbol(symbolLabel, SymbolKind.Interface, Either.forLeft(location));
EnhancedSymbolInformation enhancedSymbol = new EnhancedSymbolInformation(symbol);
context.getGeneratedSymbols().add(new CachedSymbol(context.getDocURI(), context.getLastModified(), enhancedSymbol));
context.getGeneratedSymbols().add(new CachedSymbol(context.getDocURI(), context.getLastModified(), symbol));
}
}
}

View File

@@ -32,7 +32,6 @@ import org.eclipse.lsp4j.jsonrpc.messages.Tuple.Two;
import org.slf4j.Logger;
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.utils.ASTUtils;
import org.springframework.ide.vscode.boot.java.utils.CachedSymbol;
import org.springframework.ide.vscode.boot.java.utils.SpringIndexerJavaContext;
@@ -51,11 +50,11 @@ public class FeignClientSymbolProvider extends AbstractSymbolProvider {
SpringIndexerJavaContext context, TextDocument doc) {
try {
if (node != null && node.getParent() != null && node.getParent() instanceof TypeDeclaration) {
Two<EnhancedSymbolInformation, Bean> result = createSymbol(node, annotationType, metaAnnotations, doc);
Two<WorkspaceSymbol, Bean> result = createSymbol(node, annotationType, metaAnnotations, doc);
EnhancedSymbolInformation enhancedSymbol = result.getFirst();
WorkspaceSymbol symbol = result.getFirst();
Bean beanDefinition = result.getSecond();
context.getGeneratedSymbols().add(new CachedSymbol(context.getDocURI(), context.getLastModified(), enhancedSymbol));
context.getGeneratedSymbols().add(new CachedSymbol(context.getDocURI(), context.getLastModified(), symbol));
context.getBeans().add(new CachedBean(context.getDocURI(), beanDefinition));
}
}
@@ -64,7 +63,7 @@ public class FeignClientSymbolProvider extends AbstractSymbolProvider {
}
}
private Two<EnhancedSymbolInformation, Bean> createSymbol(Annotation node, ITypeBinding annotationType, Collection<ITypeBinding> metaAnnotations, TextDocument doc) throws BadLocationException {
private Two<WorkspaceSymbol, Bean> createSymbol(Annotation node, ITypeBinding annotationType, Collection<ITypeBinding> metaAnnotations, TextDocument doc) throws BadLocationException {
String annotationTypeName = annotationType.getName();
Collection<String> metaAnnotationNames = metaAnnotations.stream()
.map(ITypeBinding::getName)
@@ -97,7 +96,7 @@ public class FeignClientSymbolProvider extends AbstractSymbolProvider {
Bean beanDefinition = new Bean(beanName, beanType == null ? "" : beanType.getQualifiedName(), location, injectionPoints, supertypes, annotations, false);
return Tuple.two(new EnhancedSymbolInformation(symbol), beanDefinition);
return Tuple.two(symbol, beanDefinition);
}
protected String beanLabel(String searchPrefix, String annotationTypeName, Collection<String> metaAnnotationNames, String beanName, String beanType) {

View File

@@ -26,7 +26,6 @@ import org.slf4j.LoggerFactory;
import org.springframework.ide.vscode.boot.java.beans.BeanUtils;
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.utils.ASTUtils;
import org.springframework.ide.vscode.boot.java.utils.CachedSymbol;
import org.springframework.ide.vscode.boot.java.utils.SpringIndexerJavaContext;
@@ -63,8 +62,6 @@ public class DataRepositorySymbolProvider extends AbstractSymbolProvider {
SymbolKind.Interface,
Either.forLeft(location));
EnhancedSymbolInformation enhancedSymbol = new EnhancedSymbolInformation(symbol);
InjectionPoint[] injectionPoints = ASTUtils.findInjectionPoints(typeDeclaration, doc);
ITypeBinding concreteBeanTypeBindung = typeDeclaration.resolveBinding();
@@ -79,7 +76,7 @@ public class DataRepositorySymbolProvider extends AbstractSymbolProvider {
Bean beanDefinition = new Bean(beanName, concreteRepoType, location, injectionPoints, supertypes, annotations, false);
context.getGeneratedSymbols().add(new CachedSymbol(context.getDocURI(), context.getLastModified(), enhancedSymbol));
context.getGeneratedSymbols().add(new CachedSymbol(context.getDocURI(), context.getLastModified(), symbol));
context.getBeans().add(new CachedBean(context.getDocURI(), beanDefinition));
} catch (BadLocationException e) {

View File

@@ -27,7 +27,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
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.utils.ASTUtils;
import org.springframework.ide.vscode.boot.java.utils.CachedSymbol;
import org.springframework.ide.vscode.boot.java.utils.SpringIndexerJavaContext;
@@ -59,8 +58,7 @@ public class EventListenerSymbolProvider extends AbstractSymbolProvider {
WorkspaceSymbol symbol = new WorkspaceSymbol(symbolLabel, SymbolKind.Interface,
Either.forLeft(new Location(doc.getUri(), doc.toRange(node.getStartPosition(), node.getLength()))));
EnhancedSymbolInformation enhancedSymbol = new EnhancedSymbolInformation(symbol);
context.getGeneratedSymbols().add(new CachedSymbol(context.getDocURI(), context.getLastModified(), enhancedSymbol));
context.getGeneratedSymbols().add(new CachedSymbol(context.getDocURI(), context.getLastModified(), symbol));
// index element for event listener

View File

@@ -1,35 +0,0 @@
/*******************************************************************************
* Copyright (c) 2018, 2025 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
* https://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Pivotal, Inc. - initial API and implementation
*******************************************************************************/
package org.springframework.ide.vscode.boot.java.handlers;
import org.eclipse.lsp4j.WorkspaceSymbol;
/**
* @author Martin Lippert
*/
public class EnhancedSymbolInformation {
private final WorkspaceSymbol symbol;
public EnhancedSymbolInformation(WorkspaceSymbol symbol) {
this.symbol = symbol;
}
public WorkspaceSymbol getSymbol() {
return symbol;
}
@Override
public String toString() {
return "EnhancedSymbolInformation [symbol=" + symbol + "]";
}
}

View File

@@ -30,12 +30,12 @@ import org.eclipse.jdt.core.dom.NormalAnnotation;
import org.eclipse.jdt.core.dom.SingleMemberAnnotation;
import org.eclipse.jdt.core.dom.TypeDeclaration;
import org.eclipse.lsp4j.Location;
import org.eclipse.lsp4j.WorkspaceSymbol;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ide.vscode.boot.java.Annotations;
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.utils.ASTUtils;
import org.springframework.ide.vscode.boot.java.utils.CachedSymbol;
import org.springframework.ide.vscode.boot.java.utils.SpringIndexerJavaContext;
@@ -73,7 +73,7 @@ public class RequestMappingSymbolProvider extends AbstractSymbolProvider {
}))
.forEach(p -> {
// symbol
EnhancedSymbolInformation symbol = RouteUtils.createRouteSymbol(location, p, methods, contentTypes, acceptTypes);
WorkspaceSymbol symbol = RouteUtils.createRouteSymbol(location, p, methods, contentTypes, acceptTypes);
context.getGeneratedSymbols().add(new CachedSymbol(context.getDocURI(), context.getLastModified(), symbol));
// index element for request mapping

View File

@@ -14,14 +14,13 @@ import org.eclipse.lsp4j.Location;
import org.eclipse.lsp4j.SymbolKind;
import org.eclipse.lsp4j.WorkspaceSymbol;
import org.eclipse.lsp4j.jsonrpc.messages.Either;
import org.springframework.ide.vscode.boot.java.handlers.EnhancedSymbolInformation;
/**
* @author Martin Lippert
*/
public class RouteUtils {
public static EnhancedSymbolInformation createRouteSymbol(Location location, String path,
public static WorkspaceSymbol createRouteSymbol(Location location, String path,
String[] httpMethods, String[] contentTypes, String[] acceptTypes) {
if (path != null && path.length() > 0) {
@@ -34,7 +33,7 @@ public class RouteUtils {
String contentType = WebfluxUtils.getStringRep(contentTypes, WebfluxUtils::getMediaType);
label += contentType != null ? " - Content-Type: " + contentType : "";
return new EnhancedSymbolInformation(new WorkspaceSymbol(label, SymbolKind.Interface, Either.forLeft(location)));
return new WorkspaceSymbol(label, SymbolKind.Interface, Either.forLeft(location));
}
else {
return null;

View File

@@ -30,9 +30,9 @@ import org.eclipse.jdt.core.dom.Type;
import org.eclipse.jdt.core.dom.TypeDeclaration;
import org.eclipse.lsp4j.Location;
import org.eclipse.lsp4j.Range;
import org.eclipse.lsp4j.WorkspaceSymbol;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ide.vscode.boot.java.handlers.EnhancedSymbolInformation;
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.SpringIndexerJava.SCAN_PASS;
@@ -131,10 +131,10 @@ public class WebfluxRouterSymbolProvider {
if (handler != null) indexElementsCollector.add(handler);
if (elements != null) indexElementsCollector.add(elements);
EnhancedSymbolInformation enhancedSymbol = RouteUtils.createRouteSymbol(location, path, getElementStrings(httpMethods),
WorkspaceSymbol symbol = RouteUtils.createRouteSymbol(location, path, getElementStrings(httpMethods),
getElementStrings(contentTypes), getElementStrings(acceptTypes));
context.getGeneratedSymbols().add(new CachedSymbol(context.getDocURI(), context.getLastModified(), enhancedSymbol));
context.getGeneratedSymbols().add(new CachedSymbol(context.getDocURI(), context.getLastModified(), symbol));
} catch (BadLocationException e) {
log.error("bad location while extracting mapping symbol for " + doc.getUri(), e);

View File

@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019, 2023 Pivotal, Inc.
* Copyright (c) 2019, 2025 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
@@ -10,21 +10,21 @@
*******************************************************************************/
package org.springframework.ide.vscode.boot.java.utils;
import org.eclipse.lsp4j.WorkspaceSymbol;
import org.springframework.ide.vscode.boot.index.cache.AbstractIndexCacheable;
import org.springframework.ide.vscode.boot.java.handlers.EnhancedSymbolInformation;
public class CachedSymbol extends AbstractIndexCacheable {
private final long lastModified;
private final EnhancedSymbolInformation enhancedSymbol;
private final WorkspaceSymbol enhancedSymbol;
public CachedSymbol(String docURI, long lastModified, EnhancedSymbolInformation enhancedSymbol) {
public CachedSymbol(String docURI, long lastModified, WorkspaceSymbol enhancedSymbol) {
super(docURI);
this.lastModified = lastModified;
this.enhancedSymbol = enhancedSymbol;
}
public EnhancedSymbolInformation getEnhancedSymbol() {
public WorkspaceSymbol getEnhancedSymbol() {
return enhancedSymbol;
}

View File

@@ -18,11 +18,11 @@ import org.eclipse.jdt.core.dom.Annotation;
import org.eclipse.jdt.core.dom.IAnnotationBinding;
import org.eclipse.jdt.core.dom.ITypeBinding;
import org.eclipse.jdt.core.dom.MethodDeclaration;
import org.eclipse.lsp4j.WorkspaceSymbol;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
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.commons.util.text.TextDocument;
/**
@@ -39,8 +39,8 @@ public class RestrictedDefaultSymbolProvider extends AbstractSymbolProvider {
// provide default symbol only in case this annotation is not combined with @Bean annotation
if (!isCombinedWithAnnotation(node, Annotations.BEAN)) {
try {
EnhancedSymbolInformation enhancedSymbol = new EnhancedSymbolInformation(DefaultSymbolProvider.provideDefaultSymbol(node, doc));
context.getGeneratedSymbols().add(new CachedSymbol(context.getDocURI(), context.getLastModified(), enhancedSymbol));
WorkspaceSymbol symbol = DefaultSymbolProvider.provideDefaultSymbol(node, doc);
context.getGeneratedSymbols().add(new CachedSymbol(context.getDocURI(), context.getLastModified(), symbol));
} catch (Exception e) {
log.warn(e.getMessage());
}

View File

@@ -39,7 +39,6 @@ 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.BeansSymbolProvider;
import org.springframework.ide.vscode.boot.java.handlers.EnhancedSymbolInformation;
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;
@@ -58,7 +57,7 @@ public class SpringFactoriesIndexer implements SpringIndexer {
// 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-9";
private static final String GENERATION = "GEN-10";
private static final String FILE_PATTERN = "**/META-INF/spring/*.factories";
@@ -96,13 +95,13 @@ public class SpringFactoriesIndexer implements SpringIndexer {
}
@Override
public List<EnhancedSymbolInformation> computeSymbols(IJavaProject project, String docURI, String content)
public List<WorkspaceSymbol> computeSymbols(IJavaProject project, String docURI, String content)
throws Exception {
return computeSymbols(docURI, content);
}
private List<EnhancedSymbolInformation> computeSymbols(String docURI, String content) {
ImmutableList.Builder<EnhancedSymbolInformation> symbols = ImmutableList.builder();
private List<WorkspaceSymbol> computeSymbols(String docURI, String content) {
ImmutableList.Builder<WorkspaceSymbol> symbols = ImmutableList.builder();
PropertiesAst ast = new AntlrParser().parse(content).ast;
if (ast != null) {
for (KeyValuePair pair : ast.getPropertyValuePairs()) {
@@ -118,10 +117,10 @@ public class SpringFactoriesIndexer implements SpringIndexer {
String simpleName = getSimpleName(fqName);
String beanId = BeanUtils.getBeanNameFromType(simpleName);
Range range = doc.toRange(new Region(pair.getOffset(), pair.getLength()));
symbols.add(new EnhancedSymbolInformation(new WorkspaceSymbol(
symbols.add(new WorkspaceSymbol(
BeansSymbolProvider.beanLabel(false, beanId, fqName, Paths.get(URI.create(docURI)).getFileName().toString()),
SymbolKind.Interface,
Either.forLeft(new Location(docURI, range)))));
Either.forLeft(new Location(docURI, range))));
} catch (Exception e) {
log.error("", e);
}
@@ -183,7 +182,7 @@ public class SpringFactoriesIndexer implements SpringIndexer {
}
if (symbols != null) {
EnhancedSymbolInformation[] enhancedSymbols = Arrays.stream(symbols).map(cachedSymbol -> cachedSymbol.getEnhancedSymbol()).toArray(EnhancedSymbolInformation[]::new);
WorkspaceSymbol[] enhancedSymbols = Arrays.stream(symbols).map(cachedSymbol -> cachedSymbol.getEnhancedSymbol()).toArray(WorkspaceSymbol[]::new);
symbolHandler.addSymbols(project, enhancedSymbols, null, null);
}
@@ -199,7 +198,7 @@ public class SpringFactoriesIndexer implements SpringIndexer {
ImmutableList.Builder<CachedSymbol> builder = ImmutableList.builder();
long lastModified = Files.getLastModifiedTime(file).toMillis();
String docUri = file.toUri().toASCIIString();
for (EnhancedSymbolInformation s : computeSymbols(docUri, content)) {
for (WorkspaceSymbol s : computeSymbols(docUri, content)) {
builder.add(new CachedSymbol(docUri, lastModified, s));
}
return builder.build();
@@ -253,7 +252,7 @@ public class SpringFactoriesIndexer implements SpringIndexer {
String file = new File(new URI(docURI)).getAbsolutePath();
this.cache.update(cacheKey, file, updatedDoc.getLastModified(), generatedSymbols, null, CachedSymbol.class);
EnhancedSymbolInformation[] symbols = generatedSymbols.stream().map(cachedSymbol -> cachedSymbol.getEnhancedSymbol()).toArray(EnhancedSymbolInformation[]::new);
WorkspaceSymbol[] symbols = generatedSymbols.stream().map(cachedSymbol -> cachedSymbol.getEnhancedSymbol()).toArray(WorkspaceSymbol[]::new);
symbolHandler.addSymbols(project, docURI, symbols, null, null);
}
}

View File

@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019, 2024 Pivotal, Inc.
* Copyright (c) 2019, 2025 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
@@ -12,7 +12,7 @@ package org.springframework.ide.vscode.boot.java.utils;
import java.util.List;
import org.springframework.ide.vscode.boot.java.handlers.EnhancedSymbolInformation;
import org.eclipse.lsp4j.WorkspaceSymbol;
import org.springframework.ide.vscode.commons.java.IJavaProject;
/**
@@ -23,7 +23,7 @@ public interface SpringIndexer {
String[] getFileWatchPatterns();
boolean isInterestedIn(String resource); // note that this might be a document URI or a standard file path on the system
List<EnhancedSymbolInformation> computeSymbols(IJavaProject project, String docURI, String content) throws Exception;
List<WorkspaceSymbol> computeSymbols(IJavaProject project, String docURI, String content) throws Exception;
void initializeProject(IJavaProject project, boolean clean) throws Exception;
void removeProject(IJavaProject project) throws Exception;

View File

@@ -58,7 +58,6 @@ import org.springframework.ide.vscode.boot.java.Annotations;
import org.springframework.ide.vscode.boot.java.annotations.AnnotationHierarchies;
import org.springframework.ide.vscode.boot.java.annotations.AnnotationHierarchyAwareLookup;
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.SymbolProvider;
import org.springframework.ide.vscode.boot.java.reconcilers.CachedDiagnostics;
import org.springframework.ide.vscode.boot.java.reconcilers.JdtReconciler;
@@ -93,7 +92,7 @@ public class SpringIndexerJava implements SpringIndexer {
// 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-13";
private static final String GENERATION = "GEN-14";
private static final String INDEX_FILES_TASK_ID = "index-java-source-files-task-";
private static final String SYMBOL_KEY = "symbols";
@@ -319,7 +318,7 @@ public class SpringIndexerJava implements SpringIndexer {
this.cache.update(diagnosticsCacheKey, file, lastModified, generatedDiagnostics, context.getDependencies(), CachedDiagnostics.class);
// dependencyTracker.dump();
EnhancedSymbolInformation[] symbols = generatedSymbols.stream().map(cachedSymbol -> cachedSymbol.getEnhancedSymbol()).toArray(EnhancedSymbolInformation[]::new);
WorkspaceSymbol[] symbols = generatedSymbols.stream().map(cachedSymbol -> cachedSymbol.getEnhancedSymbol()).toArray(WorkspaceSymbol[]::new);
List<SpringIndexElement> beans = generatedBeans.stream().filter(cachedBean -> cachedBean.getBean() != null).map(cachedBean -> cachedBean.getBean()).toList();
List<Diagnostic> diagnostics = generatedDiagnostics.stream().filter(cachedDiagnostics -> cachedDiagnostics.getDiagnostic() != null).map(cachedDiagnostic -> cachedDiagnostic.getDiagnostic()).collect(Collectors.toList());
@@ -332,7 +331,7 @@ public class SpringIndexerJava implements SpringIndexer {
}
}
public List<EnhancedSymbolInformation> computeSymbols(IJavaProject project, String docURI, String content) throws Exception {
public List<WorkspaceSymbol> computeSymbols(IJavaProject project, String docURI, String content) throws Exception {
if (content != null) {
URI uri = URI.create(docURI);
@@ -435,7 +434,7 @@ public class SpringIndexerJava implements SpringIndexer {
parser.cleanup();
}
EnhancedSymbolInformation[] symbols = generatedSymbols.stream().map(cachedSymbol -> cachedSymbol.getEnhancedSymbol()).toArray(EnhancedSymbolInformation[]::new);
WorkspaceSymbol[] symbols = generatedSymbols.stream().map(cachedSymbol -> cachedSymbol.getEnhancedSymbol()).toArray(WorkspaceSymbol[]::new);
Map<String, List<SpringIndexElement>> beans = generatedBeans.stream().filter(cachedBean -> cachedBean.getBean() != null).collect(Collectors.groupingBy(CachedBean::getDocURI, Collectors.mapping(CachedBean::getBean, Collectors.toList())));
Map<String, List<Diagnostic>> diagnosticsByDoc = generatedDiagnostics.stream().filter(cachedDiagnostic -> cachedDiagnostic.getDiagnostic() != null).collect(Collectors.groupingBy(CachedDiagnostics::getDocURI, Collectors.mapping(CachedDiagnostics::getDiagnostic, Collectors.toList())));
addEmptyDiagnostics(diagnosticsByDoc, javaFiles);
@@ -547,7 +546,7 @@ public class SpringIndexerJava implements SpringIndexer {
}
if (symbols != null && beans != null) {
EnhancedSymbolInformation[] enhancedSymbols = Arrays.stream(symbols).map(cachedSymbol -> cachedSymbol.getEnhancedSymbol()).toArray(EnhancedSymbolInformation[]::new);
WorkspaceSymbol[] enhancedSymbols = Arrays.stream(symbols).map(cachedSymbol -> cachedSymbol.getEnhancedSymbol()).toArray(WorkspaceSymbol[]::new);
Map<String, List<SpringIndexElement>> allBeans = Arrays.stream(beans).filter(cachedBean -> cachedBean.getBean() != null).collect(Collectors.groupingBy(CachedBean::getDocURI, Collectors.mapping(CachedBean::getBean, Collectors.toList())));
Map<String, List<Diagnostic>> diagnosticsByDoc = Arrays.stream(diagnostics).filter(cachedDiagnostic -> cachedDiagnostic.getDiagnostic() != null).collect(Collectors.groupingBy(CachedDiagnostics::getDocURI, Collectors.mapping(CachedDiagnostics::getDiagnostic, Collectors.toList())));
addEmptyDiagnostics(diagnosticsByDoc, javaFiles);
@@ -770,8 +769,7 @@ public class SpringIndexerJava implements SpringIndexer {
} else {
WorkspaceSymbol symbol = provideDefaultSymbol(node, context);
if (symbol != null) {
EnhancedSymbolInformation enhancedSymbol = new EnhancedSymbolInformation(symbol);
context.getGeneratedSymbols().add(new CachedSymbol(context.getDocURI(), context.getLastModified(), enhancedSymbol));
context.getGeneratedSymbols().add(new CachedSymbol(context.getDocURI(), context.getLastModified(), symbol));
}
}

View File

@@ -31,12 +31,12 @@ import org.apache.commons.io.FileUtils;
import org.eclipse.lemminx.dom.DOMDocument;
import org.eclipse.lemminx.dom.DOMNode;
import org.eclipse.lemminx.dom.DOMParser;
import org.eclipse.lsp4j.WorkspaceSymbol;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
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.CachedBean;
import org.springframework.ide.vscode.boot.java.handlers.EnhancedSymbolInformation;
import org.springframework.ide.vscode.commons.java.IClasspath;
import org.springframework.ide.vscode.commons.java.IClasspathUtil;
import org.springframework.ide.vscode.commons.java.IJavaProject;
@@ -54,7 +54,7 @@ public class SpringIndexerXML implements SpringIndexer {
// 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-8";
private static final String GENERATION = "GEN-9";
private static final String SYMBOL_KEY = "symbols";
private static final String BEANS_KEY = "beans";
@@ -141,7 +141,7 @@ public class SpringIndexerXML implements SpringIndexer {
}
if (symbols != null && beans != null) {
EnhancedSymbolInformation[] enhancedSymbols = Arrays.stream(symbols).map(cachedSymbol -> cachedSymbol.getEnhancedSymbol()).toArray(EnhancedSymbolInformation[]::new);
WorkspaceSymbol[] enhancedSymbols = Arrays.stream(symbols).map(cachedSymbol -> cachedSymbol.getEnhancedSymbol()).toArray(WorkspaceSymbol[]::new);
Map<String, List<SpringIndexElement>> allBeans = Arrays.stream(beans).filter(cachedBean -> cachedBean.getBean() != null).collect(Collectors.groupingBy(CachedBean::getDocURI, Collectors.mapping(CachedBean::getBean, Collectors.toList())));
symbolHandler.addSymbols(project, enhancedSymbols, allBeans, null);
}
@@ -179,7 +179,7 @@ public class SpringIndexerXML implements SpringIndexer {
this.cache.update(symbolsCacheKey, file, updatedDoc.getLastModified(), generatedSymbols, null, CachedSymbol.class);
this.cache.update(beansCacheKey, file, updatedDoc.getLastModified(), generatedBeans, null, CachedBean.class);
EnhancedSymbolInformation[] symbols = generatedSymbols.stream().map(cachedSymbol -> cachedSymbol.getEnhancedSymbol()).toArray(EnhancedSymbolInformation[]::new);
WorkspaceSymbol[] symbols = generatedSymbols.stream().map(cachedSymbol -> cachedSymbol.getEnhancedSymbol()).toArray(WorkspaceSymbol[]::new);
List<SpringIndexElement> beans = generatedBeans.stream().filter(cachedBean -> cachedBean.getBean() != null).map(cachedBean -> cachedBean.getBean()).toList();
symbolHandler.addSymbols(project, docURI, symbols, beans, null);
}
@@ -206,7 +206,7 @@ public class SpringIndexerXML implements SpringIndexer {
this.cache.update(symbolCacheKey, file, updatedDoc.getLastModified(), generatedSymbols, null, CachedSymbol.class);
this.cache.update(beansCacheKey, file, updatedDoc.getLastModified(), generatedBeans, null, CachedBean.class);
EnhancedSymbolInformation[] symbols = generatedSymbols.stream().map(cachedSymbol -> cachedSymbol.getEnhancedSymbol()).toArray(EnhancedSymbolInformation[]::new);
WorkspaceSymbol[] symbols = generatedSymbols.stream().map(cachedSymbol -> cachedSymbol.getEnhancedSymbol()).toArray(WorkspaceSymbol[]::new);
List<SpringIndexElement> beans = generatedBeans.stream().filter(cachedBean -> cachedBean.getBean() != null).map(cachedBean -> cachedBean.getBean()).toList();
symbolHandler.addSymbols(project, docURI, symbols, beans, null);
}
@@ -352,7 +352,7 @@ public class SpringIndexerXML implements SpringIndexer {
}
@Override
public List<EnhancedSymbolInformation> computeSymbols(IJavaProject project, String docURI, String content)
public List<WorkspaceSymbol> computeSymbols(IJavaProject project, String docURI, String content)
throws Exception {
if (content != null) {
List<CachedSymbol> generatedSymbols = new ArrayList<>();

View File

@@ -22,7 +22,6 @@ 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.CachedBean;
import org.springframework.ide.vscode.boot.java.handlers.EnhancedSymbolInformation;
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;
@@ -92,9 +91,7 @@ public class SpringIndexerXMLNamespaceHandlerBeans implements SpringIndexerXMLNa
}
WorkspaceSymbol symbol = new WorkspaceSymbol("@+ '" + beanID + "' " + beanClass, SymbolKind.Interface, Either.forLeft(new Location(docURI, range)));
EnhancedSymbolInformation fullSymbol = new EnhancedSymbolInformation(symbol);
CachedSymbol cachedSymbol = new CachedSymbol(docURI, lastModified, fullSymbol);
CachedSymbol cachedSymbol = new CachedSymbol(docURI, lastModified, symbol);
generatedSymbols.add(cachedSymbol);
// TODO: bean index

View File

@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019, 2023 Pivotal, Inc.
* Copyright (c) 2019, 2025 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
@@ -14,7 +14,7 @@ import java.util.List;
import java.util.Map;
import org.eclipse.lsp4j.Diagnostic;
import org.springframework.ide.vscode.boot.java.handlers.EnhancedSymbolInformation;
import org.eclipse.lsp4j.WorkspaceSymbol;
import org.springframework.ide.vscode.commons.java.IJavaProject;
import org.springframework.ide.vscode.commons.protocol.spring.SpringIndexElement;
@@ -23,8 +23,8 @@ import org.springframework.ide.vscode.commons.protocol.spring.SpringIndexElement
*/
public interface SymbolHandler {
void addSymbols(IJavaProject project, String docURI, EnhancedSymbolInformation[] enhancedSymbols, List<SpringIndexElement> beanDefinitions, List<Diagnostic> diagnostics);
void addSymbols(IJavaProject project, EnhancedSymbolInformation[] enhancedSymbols, Map<String, List<SpringIndexElement>> beanDefinitionsByDoc, Map<String, List<Diagnostic>> diagnosticsByDoc);
void addSymbols(IJavaProject project, String docURI, WorkspaceSymbol[] sSymbols, List<SpringIndexElement> beanDefinitions, List<Diagnostic> diagnostics);
void addSymbols(IJavaProject project, WorkspaceSymbol[] symbols, Map<String, List<SpringIndexElement>> beanDefinitionsByDoc, Map<String, List<Diagnostic>> diagnosticsByDoc);
void removeSymbols(IJavaProject project, String docURI);

View File

@@ -39,7 +39,6 @@ import org.junit.jupiter.api.Test;
import org.springframework.ide.vscode.boot.index.cache.AbstractIndexCacheable;
import org.springframework.ide.vscode.boot.index.cache.IndexCacheKey;
import org.springframework.ide.vscode.boot.index.cache.IndexCacheOnDiscDeltaBased;
import org.springframework.ide.vscode.boot.java.handlers.EnhancedSymbolInformation;
import org.springframework.ide.vscode.boot.java.utils.CachedSymbol;
import org.springframework.ide.vscode.commons.util.UriUtil;
@@ -89,8 +88,7 @@ public class IndexCacheOnDiscDeltaBasedTest {
List<CachedSymbol> generatedSymbols = new ArrayList<>();
WorkspaceSymbol symbol = new WorkspaceSymbol("symbol1", SymbolKind.Field, Either.forLeft(new Location("docURI", new Range(new Position(3, 10), new Position(3, 20)))));
EnhancedSymbolInformation enhancedSymbol = new EnhancedSymbolInformation(symbol);
generatedSymbols.add(new CachedSymbol("", timeFile1.toMillis(), enhancedSymbol));
generatedSymbols.add(new CachedSymbol("", timeFile1.toMillis(), symbol));
cache.store(CACHE_KEY_VERSION_1, files, generatedSymbols, ImmutableMultimap.of(
file1.toString(), "file1dep1",
@@ -104,9 +102,9 @@ public class IndexCacheOnDiscDeltaBasedTest {
assertNotNull(cachedSymbols);
assertEquals(1, cachedSymbols.length);
assertEquals("symbol1", cachedSymbols[0].getEnhancedSymbol().getSymbol().getName());
assertEquals(SymbolKind.Field, cachedSymbols[0].getEnhancedSymbol().getSymbol().getKind());
assertEquals(new Location("docURI", new Range(new Position(3, 10), new Position(3, 20))), cachedSymbols[0].getEnhancedSymbol().getSymbol().getLocation().getLeft());
assertEquals("symbol1", cachedSymbols[0].getEnhancedSymbol().getName());
assertEquals(SymbolKind.Field, cachedSymbols[0].getEnhancedSymbol().getKind());
assertEquals(new Location("docURI", new Range(new Position(3, 10), new Position(3, 20))), cachedSymbols[0].getEnhancedSymbol().getLocation().getLeft());
Multimap<String, String> dependencies = result.getRight();
assertEquals(2, dependencies.keySet().size());
@@ -132,8 +130,7 @@ public class IndexCacheOnDiscDeltaBasedTest {
List<CachedSymbol> generatedSymbols = new ArrayList<>();
WorkspaceSymbol symbol = new WorkspaceSymbol("symbol1", SymbolKind.Field, Either.forLeft(new Location("docURI", new Range(new Position(3, 10), new Position(3, 20)))));
EnhancedSymbolInformation enhancedSymbol = new EnhancedSymbolInformation(symbol);
generatedSymbols.add(new CachedSymbol("", timeFile1.toMillis(), enhancedSymbol));
generatedSymbols.add(new CachedSymbol("", timeFile1.toMillis(), symbol));
cache.store(CACHE_KEY_VERSION_1, files, generatedSymbols, null, CachedSymbol.class);
@@ -156,8 +153,7 @@ public class IndexCacheOnDiscDeltaBasedTest {
List<CachedSymbol> generatedSymbols = new ArrayList<>();
WorkspaceSymbol symbol = new WorkspaceSymbol("symbol1", SymbolKind.Field, Either.forLeft(new Location("docURI", new Range(new Position(3, 10), new Position(3, 20)))));
EnhancedSymbolInformation enhancedSymbol = new EnhancedSymbolInformation(symbol);
generatedSymbols.add(new CachedSymbol("", timeFile1.toMillis(), enhancedSymbol));
generatedSymbols.add(new CachedSymbol("", timeFile1.toMillis(), symbol));
cache.store(CACHE_KEY_VERSION_1, files, generatedSymbols, ImmutableMultimap.of(
file1.toString(), "file1dep",
@@ -267,20 +263,17 @@ public class IndexCacheOnDiscDeltaBasedTest {
List<CachedSymbol> generatedSymbols1 = new ArrayList<>();
WorkspaceSymbol symbol1 = new WorkspaceSymbol("symbol1", SymbolKind.Field, Either.forLeft(new Location("docURI", new Range(new Position(3, 10), new Position(3, 20)))));
EnhancedSymbolInformation enhancedSymbol1 = new EnhancedSymbolInformation(symbol1);
generatedSymbols1.add(new CachedSymbol(doc1URI, timeFile1.toMillis(), enhancedSymbol1));
generatedSymbols1.add(new CachedSymbol(doc1URI, timeFile1.toMillis(), symbol1));
cache.store(CACHE_KEY_VERSION_1, files, generatedSymbols1, null, CachedSymbol.class);
List<CachedSymbol> generatedSymbols2 = new ArrayList<>();
symbol1 = new WorkspaceSymbol("symbol1", SymbolKind.Field, Either.forLeft(new Location(doc1URI, new Range(new Position(3, 10), new Position(3, 20)))));
enhancedSymbol1 = new EnhancedSymbolInformation(symbol1);
WorkspaceSymbol symbol2 = new WorkspaceSymbol("symbol2", SymbolKind.Interface, Either.forLeft(new Location(doc1URI, new Range(new Position(5, 5), new Position(5, 10)))));
EnhancedSymbolInformation enhancedSymbol2 = new EnhancedSymbolInformation(symbol2);
generatedSymbols2.add(new CachedSymbol(doc1URI, timeFile1.toMillis() + 2000, enhancedSymbol1));
generatedSymbols2.add(new CachedSymbol(doc1URI, timeFile1.toMillis() + 2000, enhancedSymbol2));
generatedSymbols2.add(new CachedSymbol(doc1URI, timeFile1.toMillis() + 2000, symbol1));
generatedSymbols2.add(new CachedSymbol(doc1URI, timeFile1.toMillis() + 2000, symbol2));
assertTrue(file1.toFile().setLastModified(timeFile1.toMillis() + 2000));
cache.update(CACHE_KEY_VERSION_1, file1.toAbsolutePath().toString(), timeFile1.toMillis() + 2000, generatedSymbols2, null, CachedSymbol.class);
@@ -304,8 +297,7 @@ public class IndexCacheOnDiscDeltaBasedTest {
List<CachedSymbol> generatedSymbols1 = new ArrayList<>();
WorkspaceSymbol symbol1 = new WorkspaceSymbol("symbol1", SymbolKind.Field, Either.forLeft(new Location("docURI", new Range(new Position(3, 10), new Position(3, 20)))));
EnhancedSymbolInformation enhancedSymbol1 = new EnhancedSymbolInformation(symbol1);
generatedSymbols1.add(new CachedSymbol(doc1URI, timeFile1.toMillis(), enhancedSymbol1));
generatedSymbols1.add(new CachedSymbol(doc1URI, timeFile1.toMillis(), symbol1));
cache.store(CACHE_KEY_VERSION_1, files, generatedSymbols1, null, CachedSymbol.class);
@@ -368,16 +360,13 @@ public class IndexCacheOnDiscDeltaBasedTest {
List<CachedSymbol> generatedSymbols = new ArrayList<>();
WorkspaceSymbol symbol1 = new WorkspaceSymbol("symbol1", SymbolKind.Field, Either.forLeft(new Location(doc1URI, new Range(new Position(3, 10), new Position(3, 20)))));
EnhancedSymbolInformation enhancedSymbol1 = new EnhancedSymbolInformation(symbol1);
generatedSymbols.add(new CachedSymbol(doc1URI, timeFile1.toMillis(), enhancedSymbol1));
generatedSymbols.add(new CachedSymbol(doc1URI, timeFile1.toMillis(), symbol1));
WorkspaceSymbol symbol2 = new WorkspaceSymbol("symbol2", SymbolKind.Field, Either.forLeft(new Location(doc2URI, new Range(new Position(3, 10), new Position(3, 20)))));
EnhancedSymbolInformation enhancedSymbol2 = new EnhancedSymbolInformation(symbol2);
generatedSymbols.add(new CachedSymbol(doc2URI, timeFile2.toMillis(), enhancedSymbol2));
generatedSymbols.add(new CachedSymbol(doc2URI, timeFile2.toMillis(), symbol2));
WorkspaceSymbol symbol3 = new WorkspaceSymbol("symbol3", SymbolKind.Field, Either.forLeft(new Location(doc3URI, new Range(new Position(3, 10), new Position(3, 20)))));
EnhancedSymbolInformation enhancedSymbol3 = new EnhancedSymbolInformation(symbol3);
generatedSymbols.add(new CachedSymbol(doc3URI, timeFile3.toMillis(), enhancedSymbol3));
generatedSymbols.add(new CachedSymbol(doc3URI, timeFile3.toMillis(), symbol3));
// store original version of the symbols to the cache
cache.store(CACHE_KEY_VERSION_1, files, generatedSymbols, null, CachedSymbol.class);
@@ -387,18 +376,14 @@ public class IndexCacheOnDiscDeltaBasedTest {
List<CachedSymbol> updatedSymbols = new ArrayList<>();
WorkspaceSymbol updatedSymbol1 = new WorkspaceSymbol("symbol1", SymbolKind.Field, Either.forLeft(new Location(doc1URI, new Range(new Position(3, 10), new Position(3, 20)))));
EnhancedSymbolInformation updatedEnhancedSymbol1 = new EnhancedSymbolInformation(updatedSymbol1);
WorkspaceSymbol newSymbol1 = new WorkspaceSymbol("symbol1-new", SymbolKind.Interface, Either.forLeft(new Location(doc1URI, new Range(new Position(5, 5), new Position(5, 10)))));
EnhancedSymbolInformation newEnhancedSymbol1 = new EnhancedSymbolInformation(newSymbol1);
updatedSymbols.add(new CachedSymbol(doc1URI, timeFile1.toMillis() + 2000, updatedEnhancedSymbol1));
updatedSymbols.add(new CachedSymbol(doc1URI, timeFile1.toMillis() + 2000, newEnhancedSymbol1));
updatedSymbols.add(new CachedSymbol(doc1URI, timeFile1.toMillis() + 2000, updatedSymbol1));
updatedSymbols.add(new CachedSymbol(doc1URI, timeFile1.toMillis() + 2000, newSymbol1));
assertTrue(file1.toFile().setLastModified(timeFile1.toMillis() + 2000));
WorkspaceSymbol updatedSymbol2 = new WorkspaceSymbol("symbol2-updated", SymbolKind.Field, Either.forLeft(new Location(doc2URI, new Range(new Position(3, 10), new Position(3, 20)))));
EnhancedSymbolInformation updatedEnhancedSymbol2 = new EnhancedSymbolInformation(updatedSymbol2);
updatedSymbols.add(new CachedSymbol(doc2URI, timeFile2.toMillis() + 3000, updatedEnhancedSymbol2));
updatedSymbols.add(new CachedSymbol(doc2URI, timeFile2.toMillis() + 3000, updatedSymbol2));
assertTrue(file2.toFile().setLastModified(timeFile2.toMillis() + 3000));
String[] updatedFiles = new String[]{file1.toAbsolutePath().toString(), file2.toAbsolutePath().toString()};
@@ -412,27 +397,27 @@ public class IndexCacheOnDiscDeltaBasedTest {
assertNotNull(cachedSymbols);
assertEquals(4, cachedSymbols.length);
assertSymbol(updatedEnhancedSymbol1, cachedSymbols);
assertSymbol(newEnhancedSymbol1, cachedSymbols);
assertSymbol(updatedEnhancedSymbol2, cachedSymbols);
assertSymbol(enhancedSymbol3, cachedSymbols);
assertSymbol(updatedSymbol1, cachedSymbols);
assertSymbol(newSymbol1, cachedSymbols);
assertSymbol(updatedSymbol2, cachedSymbols);
assertSymbol(symbol3, cachedSymbols);
assertEquals(timeFile1.toMillis() + 2000, cache.getModificationTimestamp(CACHE_KEY_VERSION_1, file1.toString()));
assertEquals(timeFile2.toMillis() + 3000, cache.getModificationTimestamp(CACHE_KEY_VERSION_1, file2.toString()));
assertEquals(timeFile3.toMillis(), cache.getModificationTimestamp(CACHE_KEY_VERSION_1, file3.toString()));
}
private void assertSymbol(EnhancedSymbolInformation enhancedSymbol, CachedSymbol[] cachedSymbols) {
private void assertSymbol(WorkspaceSymbol enhancedSymbol, CachedSymbol[] cachedSymbols) {
for (CachedSymbol cachedSymbol : cachedSymbols) {
WorkspaceSymbol symbol = cachedSymbol.getEnhancedSymbol().getSymbol();
WorkspaceSymbol symbol = cachedSymbol.getEnhancedSymbol();
if (symbol.toString().equals(enhancedSymbol.getSymbol().toString())) {
if (symbol.toString().equals(enhancedSymbol.toString())) {
return;
}
}
fail("symbol not found: " + enhancedSymbol.getSymbol().toString());
fail("symbol not found: " + enhancedSymbol.toString());
}
@Test
@@ -471,8 +456,7 @@ public class IndexCacheOnDiscDeltaBasedTest {
List<CachedSymbol> generatedSymbols1 = new ArrayList<>();
WorkspaceSymbol symbol1 = new WorkspaceSymbol("symbol1", SymbolKind.Field, Either.forLeft(new Location("docURI", new Range(new Position(3, 10), new Position(3, 20)))));
EnhancedSymbolInformation enhancedSymbol1 = new EnhancedSymbolInformation(symbol1);
generatedSymbols1.add(new CachedSymbol(doc1URI, timeFile1.toMillis(), enhancedSymbol1));
generatedSymbols1.add(new CachedSymbol(doc1URI, timeFile1.toMillis(), symbol1));
cache.store(CACHE_KEY_VERSION_1, files, generatedSymbols1, null, CachedSymbol.class);
@@ -532,16 +516,13 @@ public class IndexCacheOnDiscDeltaBasedTest {
List<CachedSymbol> generatedSymbols1 = new ArrayList<>();
WorkspaceSymbol symbol1 = new WorkspaceSymbol("symbol1", SymbolKind.Field, Either.forLeft(new Location(doc1URI, new Range(new Position(3, 10), new Position(3, 20)))));
EnhancedSymbolInformation enhancedSymbol1 = new EnhancedSymbolInformation(symbol1);
generatedSymbols1.add(new CachedSymbol(doc1URI, timeFile1.toMillis(), enhancedSymbol1));
generatedSymbols1.add(new CachedSymbol(doc1URI, timeFile1.toMillis(), symbol1));
cache.store(CACHE_KEY_VERSION_1, files, generatedSymbols1, null, CachedSymbol.class);
List<CachedSymbol> generatedSymbols2 = new ArrayList<>();
WorkspaceSymbol symbol2 = new WorkspaceSymbol("symbol2", SymbolKind.Interface, Either.forLeft(new Location(doc2URI, new Range(new Position(5, 5), new Position(5, 10)))));
EnhancedSymbolInformation enhancedSymbol2 = new EnhancedSymbolInformation(symbol2);
generatedSymbols2.add(new CachedSymbol(doc2URI, timeFile2.toMillis(), enhancedSymbol2));
generatedSymbols2.add(new CachedSymbol(doc2URI, timeFile2.toMillis(), symbol2));
cache.update(CACHE_KEY_VERSION_1, file2.toString(), timeFile2.toMillis(), generatedSymbols2, null, CachedSymbol.class);
@@ -604,13 +585,10 @@ public class IndexCacheOnDiscDeltaBasedTest {
List<CachedSymbol> generatedSymbols = new ArrayList<>();
WorkspaceSymbol symbol1 = new WorkspaceSymbol("symbol1", SymbolKind.Field, Either.forLeft(new Location(doc1URI, new Range(new Position(3, 10), new Position(3, 20)))));
EnhancedSymbolInformation enhancedSymbol1 = new EnhancedSymbolInformation(symbol1);
WorkspaceSymbol symbol2 = new WorkspaceSymbol("symbol2", SymbolKind.Field, Either.forLeft(new Location(doc2URI, new Range(new Position(5, 10), new Position(5, 20)))));
EnhancedSymbolInformation enhancedSymbol2 = new EnhancedSymbolInformation(symbol2);
generatedSymbols.add(new CachedSymbol(doc1URI, timeFile1.toMillis(), enhancedSymbol1));
generatedSymbols.add(new CachedSymbol(doc2URI, timeFile2.toMillis(), enhancedSymbol2));
generatedSymbols.add(new CachedSymbol(doc1URI, timeFile1.toMillis(), symbol1));
generatedSymbols.add(new CachedSymbol(doc2URI, timeFile2.toMillis(), symbol2));
Multimap<String, String> dependencies = ImmutableMultimap.of(
file1.toString(), "dep1",
@@ -625,9 +603,9 @@ public class IndexCacheOnDiscDeltaBasedTest {
assertNotNull(result);
assertEquals(1, cachedSymbols.length);
assertEquals("symbol2", cachedSymbols[0].getEnhancedSymbol().getSymbol().getName());
assertEquals(SymbolKind.Field, cachedSymbols[0].getEnhancedSymbol().getSymbol().getKind());
assertEquals(new Location(doc2URI, new Range(new Position(5, 10), new Position(5, 20))), cachedSymbols[0].getEnhancedSymbol().getSymbol().getLocation().getLeft());
assertEquals("symbol2", cachedSymbols[0].getEnhancedSymbol().getName());
assertEquals(SymbolKind.Field, cachedSymbols[0].getEnhancedSymbol().getKind());
assertEquals(new Location(doc2URI, new Range(new Position(5, 10), new Position(5, 20))), cachedSymbols[0].getEnhancedSymbol().getLocation().getLeft());
Multimap<String, String> cachedDependencies = result.getRight();
assertEquals(ImmutableSet.of(), cachedDependencies.get(file1.toString()));
@@ -665,21 +643,14 @@ public class IndexCacheOnDiscDeltaBasedTest {
List<CachedSymbol> generatedSymbols = new ArrayList<>();
WorkspaceSymbol symbol1 = new WorkspaceSymbol("symbol1", SymbolKind.Field, Either.forLeft(new Location(doc1URI, new Range(new Position(3, 10), new Position(3, 20)))));
EnhancedSymbolInformation enhancedSymbol1 = new EnhancedSymbolInformation(symbol1);
WorkspaceSymbol symbol2 = new WorkspaceSymbol("symbol2", SymbolKind.Field, Either.forLeft(new Location(doc2URI, new Range(new Position(5, 10), new Position(5, 20)))));
EnhancedSymbolInformation enhancedSymbol2 = new EnhancedSymbolInformation(symbol2);
WorkspaceSymbol symbol3 = new WorkspaceSymbol("symbol3", SymbolKind.Field, Either.forLeft(new Location(doc3URI, new Range(new Position(20, 11), new Position(20, 30)))));
EnhancedSymbolInformation enhancedSymbol3 = new EnhancedSymbolInformation(symbol3);
WorkspaceSymbol symbol4 = new WorkspaceSymbol("symbol4", SymbolKind.Field, Either.forLeft(new Location(doc4URI, new Range(new Position(4, 4), new Position(5, 5)))));
EnhancedSymbolInformation enhancedSymbol4 = new EnhancedSymbolInformation(symbol4);
generatedSymbols.add(new CachedSymbol(doc1URI, timeFile1.toMillis(), enhancedSymbol1));
generatedSymbols.add(new CachedSymbol(doc2URI, timeFile2.toMillis(), enhancedSymbol2));
generatedSymbols.add(new CachedSymbol(doc3URI, timeFile3.toMillis(), enhancedSymbol3));
generatedSymbols.add(new CachedSymbol(doc4URI, timeFile4.toMillis(), enhancedSymbol4));
generatedSymbols.add(new CachedSymbol(doc1URI, timeFile1.toMillis(), symbol1));
generatedSymbols.add(new CachedSymbol(doc2URI, timeFile2.toMillis(), symbol2));
generatedSymbols.add(new CachedSymbol(doc3URI, timeFile3.toMillis(), symbol3));
generatedSymbols.add(new CachedSymbol(doc4URI, timeFile4.toMillis(), symbol4));
Multimap<String, String> dependencies = ImmutableMultimap.of(
file1.toString(), "dep1",
@@ -696,13 +667,13 @@ public class IndexCacheOnDiscDeltaBasedTest {
assertNotNull(result);
assertEquals(2, cachedSymbols.length);
assertEquals("symbol2", cachedSymbols[0].getEnhancedSymbol().getSymbol().getName());
assertEquals(SymbolKind.Field, cachedSymbols[0].getEnhancedSymbol().getSymbol().getKind());
assertEquals(new Location(doc2URI, new Range(new Position(5, 10), new Position(5, 20))), cachedSymbols[0].getEnhancedSymbol().getSymbol().getLocation().getLeft());
assertEquals("symbol2", cachedSymbols[0].getEnhancedSymbol().getName());
assertEquals(SymbolKind.Field, cachedSymbols[0].getEnhancedSymbol().getKind());
assertEquals(new Location(doc2URI, new Range(new Position(5, 10), new Position(5, 20))), cachedSymbols[0].getEnhancedSymbol().getLocation().getLeft());
assertEquals("symbol4", cachedSymbols[1].getEnhancedSymbol().getSymbol().getName());
assertEquals(SymbolKind.Field, cachedSymbols[1].getEnhancedSymbol().getSymbol().getKind());
assertEquals(new Location(doc4URI, new Range(new Position(4, 4), new Position(5, 5))), cachedSymbols[1].getEnhancedSymbol().getSymbol().getLocation().getLeft());
assertEquals("symbol4", cachedSymbols[1].getEnhancedSymbol().getName());
assertEquals(SymbolKind.Field, cachedSymbols[1].getEnhancedSymbol().getKind());
assertEquals(new Location(doc4URI, new Range(new Position(4, 4), new Position(5, 5))), cachedSymbols[1].getEnhancedSymbol().getLocation().getLeft());
Multimap<String, String> cachedDependencies = result.getRight();
assertEquals(ImmutableSet.of(), cachedDependencies.get(file1.toString()));

View File

@@ -39,7 +39,6 @@ import org.junit.jupiter.api.Test;
import org.springframework.ide.vscode.boot.index.cache.AbstractIndexCacheable;
import org.springframework.ide.vscode.boot.index.cache.IndexCacheKey;
import org.springframework.ide.vscode.boot.index.cache.IndexCacheOnDisc;
import org.springframework.ide.vscode.boot.java.handlers.EnhancedSymbolInformation;
import org.springframework.ide.vscode.boot.java.utils.CachedSymbol;
import org.springframework.ide.vscode.commons.util.UriUtil;
@@ -87,8 +86,7 @@ public class IndexCacheOnDiscTest {
List<CachedSymbol> generatedSymbols = new ArrayList<>();
WorkspaceSymbol symbol = new WorkspaceSymbol("symbol1", SymbolKind.Field, Either.forLeft(new Location("docURI", new Range(new Position(3, 10), new Position(3, 20)))));
EnhancedSymbolInformation enhancedSymbol = new EnhancedSymbolInformation(symbol);
generatedSymbols.add(new CachedSymbol("", timeFile1.toMillis(), enhancedSymbol));
generatedSymbols.add(new CachedSymbol("", timeFile1.toMillis(), symbol));
cache.store(CACHE_KEY_VERSION_1, files, generatedSymbols, ImmutableMultimap.of(
file1.toString(), "file1dep1",
@@ -102,9 +100,9 @@ public class IndexCacheOnDiscTest {
assertNotNull(cachedSymbols);
assertEquals(1, cachedSymbols.length);
assertEquals("symbol1", cachedSymbols[0].getEnhancedSymbol().getSymbol().getName());
assertEquals(SymbolKind.Field, cachedSymbols[0].getEnhancedSymbol().getSymbol().getKind());
assertEquals(new Location("docURI", new Range(new Position(3, 10), new Position(3, 20))), cachedSymbols[0].getEnhancedSymbol().getSymbol().getLocation().getLeft());
assertEquals("symbol1", cachedSymbols[0].getEnhancedSymbol().getName());
assertEquals(SymbolKind.Field, cachedSymbols[0].getEnhancedSymbol().getKind());
assertEquals(new Location("docURI", new Range(new Position(3, 10), new Position(3, 20))), cachedSymbols[0].getEnhancedSymbol().getLocation().getLeft());
Multimap<String, String> dependencies = result.getRight();
assertEquals(2, dependencies.keySet().size());
@@ -130,8 +128,7 @@ public class IndexCacheOnDiscTest {
List<CachedSymbol> generatedSymbols = new ArrayList<>();
WorkspaceSymbol symbol = new WorkspaceSymbol("symbol1", SymbolKind.Field, Either.forLeft(new Location("docURI", new Range(new Position(3, 10), new Position(3, 20)))));
EnhancedSymbolInformation enhancedSymbol = new EnhancedSymbolInformation(symbol);
generatedSymbols.add(new CachedSymbol("", timeFile1.toMillis(), enhancedSymbol));
generatedSymbols.add(new CachedSymbol("", timeFile1.toMillis(), symbol));
cache.store(CACHE_KEY_VERSION_1, files, generatedSymbols, null, CachedSymbol.class);
@@ -154,8 +151,7 @@ public class IndexCacheOnDiscTest {
List<CachedSymbol> generatedSymbols = new ArrayList<>();
WorkspaceSymbol symbol = new WorkspaceSymbol("symbol1", SymbolKind.Field, Either.forLeft(new Location("docURI", new Range(new Position(3, 10), new Position(3, 20)))));
EnhancedSymbolInformation enhancedSymbol = new EnhancedSymbolInformation(symbol);
generatedSymbols.add(new CachedSymbol("", timeFile1.toMillis(), enhancedSymbol));
generatedSymbols.add(new CachedSymbol("", timeFile1.toMillis(), symbol));
cache.store(CACHE_KEY_VERSION_1, files, generatedSymbols, ImmutableMultimap.of(
file1.toString(), "file1dep",
@@ -265,20 +261,16 @@ public class IndexCacheOnDiscTest {
List<CachedSymbol> generatedSymbols1 = new ArrayList<>();
WorkspaceSymbol symbol1 = new WorkspaceSymbol("symbol1", SymbolKind.Field, Either.forLeft(new Location("docURI", new Range(new Position(3, 10), new Position(3, 20)))));
EnhancedSymbolInformation enhancedSymbol1 = new EnhancedSymbolInformation(symbol1);
generatedSymbols1.add(new CachedSymbol(doc1URI, timeFile1.toMillis(), enhancedSymbol1));
generatedSymbols1.add(new CachedSymbol(doc1URI, timeFile1.toMillis(), symbol1));
cache.store(CACHE_KEY_VERSION_1, files, generatedSymbols1, null, CachedSymbol.class);
List<CachedSymbol> generatedSymbols2 = new ArrayList<>();
symbol1 = new WorkspaceSymbol("symbol1", SymbolKind.Field, Either.forLeft(new Location(doc1URI, new Range(new Position(3, 10), new Position(3, 20)))));
enhancedSymbol1 = new EnhancedSymbolInformation(symbol1);
WorkspaceSymbol symbol2 = new WorkspaceSymbol("symbol2", SymbolKind.Interface, Either.forLeft(new Location(doc1URI, new Range(new Position(5, 5), new Position(5, 10)))));
EnhancedSymbolInformation enhancedSymbol2 = new EnhancedSymbolInformation(symbol2);
generatedSymbols2.add(new CachedSymbol(doc1URI, timeFile1.toMillis() + 2000, enhancedSymbol1));
generatedSymbols2.add(new CachedSymbol(doc1URI, timeFile1.toMillis() + 2000, enhancedSymbol2));
generatedSymbols2.add(new CachedSymbol(doc1URI, timeFile1.toMillis() + 2000, symbol1));
generatedSymbols2.add(new CachedSymbol(doc1URI, timeFile1.toMillis() + 2000, symbol2));
assertTrue(file1.toFile().setLastModified(timeFile1.toMillis() + 2000));
cache.update(CACHE_KEY_VERSION_1, file1.toAbsolutePath().toString(), timeFile1.toMillis() + 2000, generatedSymbols2, null, CachedSymbol.class);
@@ -314,16 +306,12 @@ public class IndexCacheOnDiscTest {
List<CachedSymbol> generatedSymbols = new ArrayList<>();
WorkspaceSymbol symbol1 = new WorkspaceSymbol("symbol1", SymbolKind.Field, Either.forLeft(new Location(doc1URI, new Range(new Position(3, 10), new Position(3, 20)))));
EnhancedSymbolInformation enhancedSymbol1 = new EnhancedSymbolInformation(symbol1);
generatedSymbols.add(new CachedSymbol(doc1URI, timeFile1.toMillis(), enhancedSymbol1));
WorkspaceSymbol symbol2 = new WorkspaceSymbol("symbol2", SymbolKind.Field, Either.forLeft(new Location(doc2URI, new Range(new Position(3, 10), new Position(3, 20)))));
EnhancedSymbolInformation enhancedSymbol2 = new EnhancedSymbolInformation(symbol2);
generatedSymbols.add(new CachedSymbol(doc2URI, timeFile2.toMillis(), enhancedSymbol2));
WorkspaceSymbol symbol3 = new WorkspaceSymbol("symbol3", SymbolKind.Field, Either.forLeft(new Location(doc3URI, new Range(new Position(3, 10), new Position(3, 20)))));
EnhancedSymbolInformation enhancedSymbol3 = new EnhancedSymbolInformation(symbol3);
generatedSymbols.add(new CachedSymbol(doc3URI, timeFile3.toMillis(), enhancedSymbol3));
generatedSymbols.add(new CachedSymbol(doc1URI, timeFile1.toMillis(), symbol1));
generatedSymbols.add(new CachedSymbol(doc2URI, timeFile2.toMillis(), symbol2));
generatedSymbols.add(new CachedSymbol(doc3URI, timeFile3.toMillis(), symbol3));
// store original version of the symbols to the cache
cache.store(CACHE_KEY_VERSION_1, files, generatedSymbols, null, CachedSymbol.class);
@@ -333,18 +321,14 @@ public class IndexCacheOnDiscTest {
List<CachedSymbol> updatedSymbols = new ArrayList<>();
WorkspaceSymbol updatedSymbol1 = new WorkspaceSymbol("symbol1", SymbolKind.Field, Either.forLeft(new Location(doc1URI, new Range(new Position(3, 10), new Position(3, 20)))));
EnhancedSymbolInformation updatedEnhancedSymbol1 = new EnhancedSymbolInformation(updatedSymbol1);
WorkspaceSymbol newSymbol1 = new WorkspaceSymbol("symbol1-new", SymbolKind.Interface, Either.forLeft(new Location(doc1URI, new Range(new Position(5, 5), new Position(5, 10)))));
EnhancedSymbolInformation newEnhancedSymbol1 = new EnhancedSymbolInformation(newSymbol1);
updatedSymbols.add(new CachedSymbol(doc1URI, timeFile1.toMillis() + 2000, updatedEnhancedSymbol1));
updatedSymbols.add(new CachedSymbol(doc1URI, timeFile1.toMillis() + 2000, newEnhancedSymbol1));
updatedSymbols.add(new CachedSymbol(doc1URI, timeFile1.toMillis() + 2000, updatedSymbol1));
updatedSymbols.add(new CachedSymbol(doc1URI, timeFile1.toMillis() + 2000, newSymbol1));
assertTrue(file1.toFile().setLastModified(timeFile1.toMillis() + 2000));
WorkspaceSymbol updatedSymbol2 = new WorkspaceSymbol("symbol2-updated", SymbolKind.Field, Either.forLeft(new Location(doc2URI, new Range(new Position(3, 10), new Position(3, 20)))));
EnhancedSymbolInformation updatedEnhancedSymbol2 = new EnhancedSymbolInformation(updatedSymbol2);
updatedSymbols.add(new CachedSymbol(doc2URI, timeFile2.toMillis() + 3000, updatedEnhancedSymbol2));
updatedSymbols.add(new CachedSymbol(doc2URI, timeFile2.toMillis() + 3000, updatedSymbol2));
assertTrue(file2.toFile().setLastModified(timeFile2.toMillis() + 3000));
String[] updatedFiles = new String[]{file1.toAbsolutePath().toString(), file2.toAbsolutePath().toString()};
@@ -358,27 +342,27 @@ public class IndexCacheOnDiscTest {
assertNotNull(cachedSymbols);
assertEquals(4, cachedSymbols.length);
assertSymbol(updatedEnhancedSymbol1, cachedSymbols);
assertSymbol(newEnhancedSymbol1, cachedSymbols);
assertSymbol(updatedEnhancedSymbol2, cachedSymbols);
assertSymbol(enhancedSymbol3, cachedSymbols);
assertSymbol(updatedSymbol1, cachedSymbols);
assertSymbol(newSymbol1, cachedSymbols);
assertSymbol(updatedSymbol2, cachedSymbols);
assertSymbol(symbol3, cachedSymbols);
assertEquals(timeFile1.toMillis() + 2000, cache.getModificationTimestamp(CACHE_KEY_VERSION_1, file1.toString()));
assertEquals(timeFile2.toMillis() + 3000, cache.getModificationTimestamp(CACHE_KEY_VERSION_1, file2.toString()));
assertEquals(timeFile3.toMillis(), cache.getModificationTimestamp(CACHE_KEY_VERSION_1, file3.toString()));
}
private void assertSymbol(EnhancedSymbolInformation enhancedSymbol, CachedSymbol[] cachedSymbols) {
private void assertSymbol(WorkspaceSymbol enhancedSymbol, CachedSymbol[] cachedSymbols) {
for (CachedSymbol cachedSymbol : cachedSymbols) {
WorkspaceSymbol symbol = cachedSymbol.getEnhancedSymbol().getSymbol();
WorkspaceSymbol symbol = cachedSymbol.getEnhancedSymbol();
if (symbol.toString().equals(enhancedSymbol.getSymbol().toString())) {
if (symbol.toString().equals(enhancedSymbol.toString())) {
return;
}
}
fail("symbol not found: " + enhancedSymbol.getSymbol().toString());
fail("symbol not found: " + enhancedSymbol.toString());
}
@Test
@@ -417,8 +401,7 @@ public class IndexCacheOnDiscTest {
List<CachedSymbol> generatedSymbols1 = new ArrayList<>();
WorkspaceSymbol symbol1 = new WorkspaceSymbol("symbol1", SymbolKind.Field, Either.forLeft(new Location("docURI", new Range(new Position(3, 10), new Position(3, 20)))));
EnhancedSymbolInformation enhancedSymbol1 = new EnhancedSymbolInformation(symbol1);
generatedSymbols1.add(new CachedSymbol(doc1URI, timeFile1.toMillis(), enhancedSymbol1));
generatedSymbols1.add(new CachedSymbol(doc1URI, timeFile1.toMillis(), symbol1));
cache.store(CACHE_KEY_VERSION_1, files, generatedSymbols1, null, CachedSymbol.class);
@@ -478,16 +461,14 @@ public class IndexCacheOnDiscTest {
List<CachedSymbol> generatedSymbols1 = new ArrayList<>();
WorkspaceSymbol symbol1 = new WorkspaceSymbol("symbol1", SymbolKind.Field, Either.forLeft(new Location(doc1URI, new Range(new Position(3, 10), new Position(3, 20)))));
EnhancedSymbolInformation enhancedSymbol1 = new EnhancedSymbolInformation(symbol1);
generatedSymbols1.add(new CachedSymbol(doc1URI, timeFile1.toMillis(), enhancedSymbol1));
generatedSymbols1.add(new CachedSymbol(doc1URI, timeFile1.toMillis(), symbol1));
cache.store(CACHE_KEY_VERSION_1, files, generatedSymbols1, null, CachedSymbol.class);
List<CachedSymbol> generatedSymbols2 = new ArrayList<>();
WorkspaceSymbol symbol2 = new WorkspaceSymbol("symbol2", SymbolKind.Interface, Either.forLeft(new Location(doc2URI, new Range(new Position(5, 5), new Position(5, 10)))));
EnhancedSymbolInformation enhancedSymbol2 = new EnhancedSymbolInformation(symbol2);
generatedSymbols2.add(new CachedSymbol(doc2URI, timeFile2.toMillis(), enhancedSymbol2));
generatedSymbols2.add(new CachedSymbol(doc2URI, timeFile2.toMillis(), symbol2));
cache.update(CACHE_KEY_VERSION_1, file2.toString(), timeFile2.toMillis(), generatedSymbols2, null, CachedSymbol.class);
@@ -550,13 +531,10 @@ public class IndexCacheOnDiscTest {
List<CachedSymbol> generatedSymbols = new ArrayList<>();
WorkspaceSymbol symbol1 = new WorkspaceSymbol("symbol1", SymbolKind.Field, Either.forLeft(new Location(doc1URI, new Range(new Position(3, 10), new Position(3, 20)))));
EnhancedSymbolInformation enhancedSymbol1 = new EnhancedSymbolInformation(symbol1);
WorkspaceSymbol symbol2 = new WorkspaceSymbol("symbol2", SymbolKind.Field, Either.forLeft(new Location(doc2URI, new Range(new Position(5, 10), new Position(5, 20)))));
EnhancedSymbolInformation enhancedSymbol2 = new EnhancedSymbolInformation(symbol2);
generatedSymbols.add(new CachedSymbol(doc1URI, timeFile1.toMillis(), enhancedSymbol1));
generatedSymbols.add(new CachedSymbol(doc2URI, timeFile2.toMillis(), enhancedSymbol2));
generatedSymbols.add(new CachedSymbol(doc1URI, timeFile1.toMillis(), symbol1));
generatedSymbols.add(new CachedSymbol(doc2URI, timeFile2.toMillis(), symbol2));
Multimap<String, String> dependencies = ImmutableMultimap.of(
file1.toString(), "dep1",
@@ -571,9 +549,9 @@ public class IndexCacheOnDiscTest {
assertNotNull(result);
assertEquals(1, cachedSymbols.length);
assertEquals("symbol2", cachedSymbols[0].getEnhancedSymbol().getSymbol().getName());
assertEquals(SymbolKind.Field, cachedSymbols[0].getEnhancedSymbol().getSymbol().getKind());
assertEquals(new Location(doc2URI, new Range(new Position(5, 10), new Position(5, 20))), cachedSymbols[0].getEnhancedSymbol().getSymbol().getLocation().getLeft());
assertEquals("symbol2", cachedSymbols[0].getEnhancedSymbol().getName());
assertEquals(SymbolKind.Field, cachedSymbols[0].getEnhancedSymbol().getKind());
assertEquals(new Location(doc2URI, new Range(new Position(5, 10), new Position(5, 20))), cachedSymbols[0].getEnhancedSymbol().getLocation().getLeft());
Multimap<String, String> cachedDependencies = result.getRight();
assertEquals(ImmutableSet.of(), cachedDependencies.get(file1.toString()));
@@ -611,21 +589,14 @@ public class IndexCacheOnDiscTest {
List<CachedSymbol> generatedSymbols = new ArrayList<>();
WorkspaceSymbol symbol1 = new WorkspaceSymbol("symbol1", SymbolKind.Field, Either.forLeft(new Location(doc1URI, new Range(new Position(3, 10), new Position(3, 20)))));
EnhancedSymbolInformation enhancedSymbol1 = new EnhancedSymbolInformation(symbol1);
WorkspaceSymbol symbol2 = new WorkspaceSymbol("symbol2", SymbolKind.Field, Either.forLeft(new Location(doc2URI, new Range(new Position(5, 10), new Position(5, 20)))));
EnhancedSymbolInformation enhancedSymbol2 = new EnhancedSymbolInformation(symbol2);
WorkspaceSymbol symbol3 = new WorkspaceSymbol("symbol3", SymbolKind.Field, Either.forLeft(new Location(doc3URI, new Range(new Position(20, 11), new Position(20, 30)))));
EnhancedSymbolInformation enhancedSymbol3 = new EnhancedSymbolInformation(symbol3);
WorkspaceSymbol symbol4 = new WorkspaceSymbol("symbol4", SymbolKind.Field, Either.forLeft(new Location(doc4URI, new Range(new Position(4, 4), new Position(5, 5)))));
EnhancedSymbolInformation enhancedSymbol4 = new EnhancedSymbolInformation(symbol4);
generatedSymbols.add(new CachedSymbol(doc1URI, timeFile1.toMillis(), enhancedSymbol1));
generatedSymbols.add(new CachedSymbol(doc2URI, timeFile2.toMillis(), enhancedSymbol2));
generatedSymbols.add(new CachedSymbol(doc3URI, timeFile3.toMillis(), enhancedSymbol3));
generatedSymbols.add(new CachedSymbol(doc4URI, timeFile4.toMillis(), enhancedSymbol4));
generatedSymbols.add(new CachedSymbol(doc1URI, timeFile1.toMillis(), symbol1));
generatedSymbols.add(new CachedSymbol(doc2URI, timeFile2.toMillis(), symbol2));
generatedSymbols.add(new CachedSymbol(doc3URI, timeFile3.toMillis(), symbol3));
generatedSymbols.add(new CachedSymbol(doc4URI, timeFile4.toMillis(), symbol4));
Multimap<String, String> dependencies = ImmutableMultimap.of(
file1.toString(), "dep1",
@@ -642,13 +613,13 @@ public class IndexCacheOnDiscTest {
assertNotNull(result);
assertEquals(2, cachedSymbols.length);
assertEquals("symbol2", cachedSymbols[0].getEnhancedSymbol().getSymbol().getName());
assertEquals(SymbolKind.Field, cachedSymbols[0].getEnhancedSymbol().getSymbol().getKind());
assertEquals(new Location(doc2URI, new Range(new Position(5, 10), new Position(5, 20))), cachedSymbols[0].getEnhancedSymbol().getSymbol().getLocation().getLeft());
assertEquals("symbol2", cachedSymbols[0].getEnhancedSymbol().getName());
assertEquals(SymbolKind.Field, cachedSymbols[0].getEnhancedSymbol().getKind());
assertEquals(new Location(doc2URI, new Range(new Position(5, 10), new Position(5, 20))), cachedSymbols[0].getEnhancedSymbol().getLocation().getLeft());
assertEquals("symbol4", cachedSymbols[1].getEnhancedSymbol().getSymbol().getName());
assertEquals(SymbolKind.Field, cachedSymbols[1].getEnhancedSymbol().getSymbol().getKind());
assertEquals(new Location(doc4URI, new Range(new Position(4, 4), new Position(5, 5))), cachedSymbols[1].getEnhancedSymbol().getSymbol().getLocation().getLeft());
assertEquals("symbol4", cachedSymbols[1].getEnhancedSymbol().getName());
assertEquals(SymbolKind.Field, cachedSymbols[1].getEnhancedSymbol().getKind());
assertEquals(new Location(doc4URI, new Range(new Position(4, 4), new Position(5, 5))), cachedSymbols[1].getEnhancedSymbol().getLocation().getLeft());
Multimap<String, String> cachedDependencies = result.getRight();
assertEquals(ImmutableSet.of(), cachedDependencies.get(file1.toString()));