Skip to content

Commit

Permalink
GH-1041: finally removing main obsolete symbol add-on information int…
Browse files Browse the repository at this point in the history
…erface
  • Loading branch information
martinlippert committed Jan 16, 2025
1 parent ad39b9f commit 778cacf
Show file tree
Hide file tree
Showing 18 changed files with 65 additions and 194 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2017, 2024 Pivotal, Inc.
* Copyright (c) 2017, 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
Expand All @@ -25,7 +25,6 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
Expand Down Expand Up @@ -57,7 +56,6 @@
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.SymbolAddOnInformation;
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;
Expand Down Expand Up @@ -747,42 +745,6 @@ public List<? extends WorkspaceSymbol> getSymbols(String docURI) {
}
}

public List<SymbolAddOnInformation> getAllAdditionalInformation(Predicate<SymbolAddOnInformation> filter) {
if (filter != null) {
synchronized(symbols) {
return symbols.stream()
.map(s -> s.getAdditionalInformation())
.filter(Objects::nonNull)
.flatMap(i -> Arrays.stream(i))
.filter(filter)
.collect(Collectors.toList());
}
}
else {
return Collections.emptyList();
}
}

public List<? extends SymbolAddOnInformation> getAdditonalInformation(String docURI) {
List<EnhancedSymbolInformation> info = this.symbolsByDoc.get(docURI);

if (info != null) {
synchronized(info) {
ImmutableList.Builder<SymbolAddOnInformation> builder = ImmutableList.builder();
for (EnhancedSymbolInformation enhanced : info) {
SymbolAddOnInformation[] additionalInformation = enhanced.getAdditionalInformation();
if (additionalInformation != null) {
builder.add(additionalInformation);
}
}
return builder.build();
}
}
else {
return Collections.emptyList();
}
}

@Override
public CompletableFuture<List<Bean>> beans(BeansParams params) {
String projectName = params.getProjectName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import org.eclipse.lsp4j.Location;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ide.vscode.boot.java.handlers.SymbolAddOnInformation;
import org.springframework.ide.vscode.commons.protocol.spring.AnnotationMetadata;
import org.springframework.ide.vscode.commons.protocol.spring.Bean;
import org.springframework.ide.vscode.commons.protocol.spring.DefaultValues;
Expand All @@ -52,9 +51,6 @@
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import com.google.gson.JsonPrimitive;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import com.google.gson.reflect.TypeToken;
import com.google.gson.stream.JsonReader;

Expand Down Expand Up @@ -351,7 +347,6 @@ else if (key != null && !key.equals(cacheKey)

public static Gson createGson() {
return new GsonBuilder()
.registerTypeAdapter(SymbolAddOnInformation.class, new SymbolAddOnInformationAdapter())
.registerTypeAdapter(Bean.class, new BeanJsonAdapter())
.registerTypeAdapter(InjectionPoint.class, new InjectionPointJsonAdapter())
.registerTypeAdapter(IndexCacheStore.class, new IndexCacheStoreAdapter())
Expand Down Expand Up @@ -426,33 +421,6 @@ public IndexCacheStore<?> deserialize(JsonElement json, Type typeOfT, JsonDeseri

}

/**
* gson adapter to store subtype information for symbol addon informations
*/
private static class SymbolAddOnInformationAdapter implements JsonSerializer<SymbolAddOnInformation>, JsonDeserializer<SymbolAddOnInformation> {

@Override
public JsonElement serialize(SymbolAddOnInformation addonInfo, Type typeOfSrc, JsonSerializationContext context) {
JsonObject result = new JsonObject();
result.add("type", new JsonPrimitive(addonInfo.getClass().getName()));
result.add("data", context.serialize(addonInfo));
return result;
}

@Override
public SymbolAddOnInformation deserialize(JsonElement json, Type type, JsonDeserializationContext context) throws JsonParseException {
JsonObject parsedObject = json.getAsJsonObject();
String className = parsedObject.get("type").getAsString();
JsonElement element = parsedObject.get("data");

try {
return context.deserialize(element, Class.forName(className));
} catch (ClassNotFoundException cnfe) {
throw new JsonParseException("cannot parse data from unknown SymbolAddOnInformation subtype: " + type, cnfe);
}
}
}

/**
* gson adapter to store subtype information for beans
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
import org.eclipse.lsp4j.Location;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ide.vscode.boot.java.handlers.SymbolAddOnInformation;
import org.springframework.ide.vscode.commons.protocol.spring.AnnotationMetadata;
import org.springframework.ide.vscode.commons.protocol.spring.Bean;
import org.springframework.ide.vscode.commons.protocol.spring.DefaultValues;
Expand Down Expand Up @@ -371,7 +370,6 @@ private <T extends IndexCacheable> Pair<IndexCacheStore<T>, Integer> retrieveSto
public static Gson createGson() {
return new GsonBuilder()
.registerTypeAdapter(DeltaStorage.class, new DeltaStorageAdapter())
.registerTypeAdapter(SymbolAddOnInformation.class, new SymbolAddOnInformationAdapter())
.registerTypeAdapter(Bean.class, new BeanJsonAdapter())
.registerTypeAdapter(InjectionPoint.class, new InjectionPointJsonAdapter())
.registerTypeAdapter(IndexCacheStore.class, new IndexCacheStoreAdapter())
Expand Down Expand Up @@ -637,30 +635,6 @@ public DeltaStorage<?> deserialize(JsonElement json, Type type, JsonDeserializat
}
}

private static class SymbolAddOnInformationAdapter implements JsonSerializer<SymbolAddOnInformation>, JsonDeserializer<SymbolAddOnInformation> {

@Override
public JsonElement serialize(SymbolAddOnInformation addonInfo, Type typeOfSrc, JsonSerializationContext context) {
JsonObject result = new JsonObject();
result.add("type", new JsonPrimitive(addonInfo.getClass().getName()));
result.add("data", context.serialize(addonInfo));
return result;
}

@Override
public SymbolAddOnInformation deserialize(JsonElement json, Type type, JsonDeserializationContext context) throws JsonParseException {
JsonObject parsedObject = json.getAsJsonObject();
String className = parsedObject.get("type").getAsString();
JsonElement element = parsedObject.get("data");

try {
return context.deserialize(element, Class.forName(className));
} catch (ClassNotFoundException cnfe) {
throw new JsonParseException("cannot parse data from unknown SymbolAddOnInformation subtype: " + type, cnfe);
}
}
}

private static class BeanJsonAdapter implements JsonDeserializer<Bean> {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@
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;
import org.springframework.ide.vscode.boot.java.utils.SpringIndexerJavaContext;
import org.springframework.ide.vscode.boot.java.utils.SpringIndexerJava.SCAN_PASS;
import org.springframework.ide.vscode.boot.java.utils.SpringIndexerJavaContext;
import org.springframework.ide.vscode.commons.protocol.spring.AnnotationMetadata;
import org.springframework.ide.vscode.commons.protocol.spring.Bean;
import org.springframework.ide.vscode.commons.protocol.spring.InjectionPoint;
Expand Down Expand Up @@ -103,8 +103,7 @@ public void addSymbols(Annotation node, ITypeBinding typeBinding, Collection<ITy
new WorkspaceSymbol(
beanLabel(isFunction, nameAndRegion.getT1(), beanType.getName(), "@Bean" + markerString),
SymbolKind.Interface,
Either.forLeft(location)),
null
Either.forLeft(location))
);

InjectionPoint[] injectionPoints = ASTUtils.findInjectionPoints(method, doc);
Expand Down Expand Up @@ -142,7 +141,7 @@ protected void addSymbolsPass1(TypeDeclaration typeDeclaration, SpringIndexerJav
Either.forLeft(beanLocation));

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


ITypeBinding concreteBeanType = typeDeclaration.resolveBinding();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ protected void addSymbolsPass1(Annotation node, ITypeBinding annotationType, Col
}
else if (Annotations.NAMED_ANNOTATIONS.contains(annotationType.getQualifiedName())) {
WorkspaceSymbol symbol = DefaultSymbolProvider.provideDefaultSymbol(node, doc);
EnhancedSymbolInformation enhancedSymbol = new EnhancedSymbolInformation(symbol, null);
EnhancedSymbolInformation enhancedSymbol = new EnhancedSymbolInformation(symbol);
context.getGeneratedSymbols().add(new CachedSymbol(context.getDocURI(), context.getLastModified(), enhancedSymbol));
}
}
Expand Down Expand Up @@ -108,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, null), beanDefinition);
return Tuple.two(new EnhancedSymbolInformation(symbol), 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 @@ -97,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, null), beanDefinition);
return Tuple.two(new EnhancedSymbolInformation(symbol), 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 @@ -63,7 +63,7 @@ protected void addSymbolsPass1(TypeDeclaration typeDeclaration, SpringIndexerJav
SymbolKind.Interface,
Either.forLeft(location));

EnhancedSymbolInformation enhancedSymbol = new EnhancedSymbolInformation(symbol, null);
EnhancedSymbolInformation enhancedSymbol = new EnhancedSymbolInformation(symbol);

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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2018, 2022 Pivotal, Inc.
* 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
Expand All @@ -18,21 +18,15 @@
public class EnhancedSymbolInformation {

private final WorkspaceSymbol symbol;
private final SymbolAddOnInformation[] additionalInformation;

public EnhancedSymbolInformation(WorkspaceSymbol symbol, SymbolAddOnInformation[] additionalInformation) {
public EnhancedSymbolInformation(WorkspaceSymbol symbol) {
this.symbol = symbol;
this.additionalInformation = additionalInformation;
}

public WorkspaceSymbol getSymbol() {
return symbol;
}

public SymbolAddOnInformation[] getAdditionalInformation() {
return additionalInformation;
}

@Override
public String toString() {
return "EnhancedSymbolInformation [symbol=" + symbol + "]";
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2017, 2024 Pivotal, Inc.
* Copyright (c) 2017, 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
Expand Down Expand Up @@ -69,7 +69,7 @@ protected void addSymbolsPass1(Annotation node, ITypeBinding annotationType, Col
.filter(Objects::nonNull).map(p -> {
return combinePath(parent, p);
}))
.map(p -> RouteUtils.createRouteSymbol(location, p, methods, contentTypes, acceptTypes, null))
.map(p -> RouteUtils.createRouteSymbol(location, p, methods, contentTypes, acceptTypes))
.forEach((enhancedSymbol) -> context.getGeneratedSymbols().add(new CachedSymbol(context.getDocURI(), context.getLastModified(), enhancedSymbol)));
} catch (Exception e) {
log.error("problem occured while scanning for request mapping symbols from " + doc.getUri(), e);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2018 Pivotal, Inc.
* 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
Expand All @@ -15,15 +15,14 @@
import org.eclipse.lsp4j.WorkspaceSymbol;
import org.eclipse.lsp4j.jsonrpc.messages.Either;
import org.springframework.ide.vscode.boot.java.handlers.EnhancedSymbolInformation;
import org.springframework.ide.vscode.boot.java.handlers.SymbolAddOnInformation;

/**
* @author Martin Lippert
*/
public class RouteUtils {

public static EnhancedSymbolInformation createRouteSymbol(Location location, String path,
String[] httpMethods, String[] contentTypes, String[] acceptTypes, SymbolAddOnInformation[] enhancedInformation) {
String[] httpMethods, String[] contentTypes, String[] acceptTypes) {

if (path != null && path.length() > 0) {
String label = "@" + (path.startsWith("/") ? path : ("/" + path));
Expand All @@ -35,7 +34,7 @@ public static EnhancedSymbolInformation createRouteSymbol(Location location, Str
String contentType = WebfluxUtils.getStringRep(contentTypes, WebfluxUtils::getMediaType);
label += contentType != null ? " - Content-Type: " + contentType : "";

return new EnhancedSymbolInformation(new WorkspaceSymbol(label, SymbolKind.Interface, Either.forLeft(location)), enhancedInformation);
return new EnhancedSymbolInformation(new WorkspaceSymbol(label, SymbolKind.Interface, Either.forLeft(location)));
}
else {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ protected static void extractMappingSymbol(MethodInvocation node, TextDocument d
if (elements != null) indexElementsCollector.add(elements);

EnhancedSymbolInformation enhancedSymbol = RouteUtils.createRouteSymbol(location, path, getElementStrings(httpMethods),
getElementStrings(contentTypes), getElementStrings(acceptTypes), null);
getElementStrings(contentTypes), getElementStrings(acceptTypes));

context.getGeneratedSymbols().add(new CachedSymbol(context.getDocURI(), context.getLastModified(), enhancedSymbol));

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2018, 2023 Pivotal, Inc.
* 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
Expand Down Expand Up @@ -39,7 +39,7 @@ protected void addSymbolsPass1(Annotation node, ITypeBinding typeBinding,
// 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), null);
EnhancedSymbolInformation enhancedSymbol = new EnhancedSymbolInformation(DefaultSymbolProvider.provideDefaultSymbol(node, doc));
context.getGeneratedSymbols().add(new CachedSymbol(context.getDocURI(), context.getLastModified(), enhancedSymbol));
} catch (Exception e) {
log.warn(e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +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))), null));
Either.forLeft(new Location(docURI, range)))));
} catch (Exception e) {
log.error("", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -770,7 +770,7 @@ private void extractSymbolInformation(Annotation node, final SpringIndexerJavaCo
} else {
WorkspaceSymbol symbol = provideDefaultSymbol(node, context);
if (symbol != null) {
EnhancedSymbolInformation enhancedSymbol = new EnhancedSymbolInformation(symbol, null);
EnhancedSymbolInformation enhancedSymbol = new EnhancedSymbolInformation(symbol);
context.getGeneratedSymbols().add(new CachedSymbol(context.getDocURI(), context.getLastModified(), enhancedSymbol));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ else if (name != null && name.equals("class")) {
}

WorkspaceSymbol symbol = new WorkspaceSymbol("@+ '" + beanID + "' " + beanClass, SymbolKind.Interface, Either.forLeft(new Location(docURI, range)));
EnhancedSymbolInformation fullSymbol = new EnhancedSymbolInformation(symbol, null);
EnhancedSymbolInformation fullSymbol = new EnhancedSymbolInformation(symbol);

CachedSymbol cachedSymbol = new CachedSymbol(docURI, lastModified, fullSymbol);
generatedSymbols.add(cachedSymbol);
Expand Down
Loading

0 comments on commit 778cacf

Please sign in to comment.