From 6cc3086b0e2a73d2e66d38b41536c0247802cec1 Mon Sep 17 00:00:00 2001 From: aboyko Date: Wed, 16 Apr 2025 23:47:58 -0400 Subject: [PATCH] Don't include java.lang.Object in supertypes serialization Signed-off-by: aboyko --- .../vscode/commons/protocol/spring/Bean.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/headless-services/commons/commons-lsp-extensions/src/main/java/org/springframework/ide/vscode/commons/protocol/spring/Bean.java b/headless-services/commons/commons-lsp-extensions/src/main/java/org/springframework/ide/vscode/commons/protocol/spring/Bean.java index fd18880cd..3bfbdc844 100644 --- a/headless-services/commons/commons-lsp-extensions/src/main/java/org/springframework/ide/vscode/commons/protocol/spring/Bean.java +++ b/headless-services/commons/commons-lsp-extensions/src/main/java/org/springframework/ide/vscode/commons/protocol/spring/Bean.java @@ -11,11 +11,13 @@ package org.springframework.ide.vscode.commons.protocol.spring; import java.util.Set; +import java.util.stream.Collectors; import org.eclipse.lsp4j.DocumentSymbol; import org.eclipse.lsp4j.Location; import org.eclipse.lsp4j.SymbolKind; +import com.google.common.collect.ImmutableSet; import com.google.gson.Gson; public class Bean extends AbstractSpringIndexElement implements SymbolElement { @@ -28,6 +30,7 @@ public class Bean extends AbstractSpringIndexElement implements SymbolElement { private final AnnotationMetadata[] annotations; private final boolean isConfiguration; private final String symbolLabel; + private final boolean isInterface; public Bean( String name, @@ -44,6 +47,7 @@ public class Bean extends AbstractSpringIndexElement implements SymbolElement { this.location = location; this.isConfiguration = isConfiguration; this.symbolLabel = symbolLabel; + this.isInterface = supertypes == null || !supertypes.contains(Object.class.getName()); if (injectionPoints != null && injectionPoints.length == 0) { this.injectionPoints = null; @@ -52,11 +56,12 @@ public class Bean extends AbstractSpringIndexElement implements SymbolElement { this.injectionPoints = injectionPoints; } - if (supertypes != null && supertypes.size() == 0) { + Set sanitizedSuperTypes = supertypes == null ? null : supertypes.stream().filter(t -> !t.equals(Object.class.getName())).collect(Collectors.toUnmodifiableSet()); + if (sanitizedSuperTypes != null && sanitizedSuperTypes.size() == 0) { this.supertypes = null; } else { - this.supertypes = supertypes; + this.supertypes = sanitizedSuperTypes; } if (annotations != null && annotations.length == 0) { @@ -84,7 +89,7 @@ public class Bean extends AbstractSpringIndexElement implements SymbolElement { } public boolean isTypeCompatibleWith(String type) { - return type != null && ((this.type != null && this.type.equals(type)) || (getSupertypes().contains(type))); + return type != null && ((this.type != null && this.type.equals(type)) || (supertypes != null && supertypes.contains(type)) || (Object.class.getName().equals(type) && !isInterface)); } public AnnotationMetadata[] getAnnotations() { @@ -96,7 +101,11 @@ public class Bean extends AbstractSpringIndexElement implements SymbolElement { } public Set getSupertypes() { - return supertypes == null ? DefaultValues.EMPTY_SUPERTYPES : supertypes; + if (supertypes == null) { + return isInterface ? DefaultValues.EMPTY_SUPERTYPES : DefaultValues.OBJECT_SUPERTYPE; + } else { + return isInterface ? supertypes : ImmutableSet.builder().addAll(supertypes).add(Object.class.getName()).build(); + } } public String getSymbolLabel() {