diff --git a/magik-language-server/src/main/java/nl/ramsolutions/sw/magik/languageserver/hover/HoverProvider.java b/magik-language-server/src/main/java/nl/ramsolutions/sw/magik/languageserver/hover/HoverProvider.java index b157f5dd..179eeb8a 100644 --- a/magik-language-server/src/main/java/nl/ramsolutions/sw/magik/languageserver/hover/HoverProvider.java +++ b/magik-language-server/src/main/java/nl/ramsolutions/sw/magik/languageserver/hover/HoverProvider.java @@ -466,9 +466,10 @@ private void buildMethodSignatureDoc(final Method method, final StringBuilder bu private void buildTypeSignatureDoc(final AbstractType type, final StringBuilder builder) { // Type signature. + final TypeString typeStr = type.getTypeString(); builder .append("## ") - .append(type.getFullName()) + .append(typeStr.getFullString().replace("<", "<").replace(">", ">")) .append(SECTION_END); // Type doc. @@ -502,12 +503,12 @@ private void buildTypeSignatureDoc(final AbstractType type, final StringBuilder .append(SECTION_END); } - // Type generics. - final Collection generics = type.getGenerics(); - if (!generics.isEmpty()) { + // Type generic declarations. + final Collection genericDeclarations = type.getGenerics(); + if (!genericDeclarations.isEmpty()) { builder - .append("## Generics\n"); - generics.stream() + .append("## Generic declarations\n"); + genericDeclarations.stream() .forEach(generic -> builder .append("* ") diff --git a/magik-squid/src/main/java/nl/ramsolutions/sw/magik/analysis/typing/indexer/MagikIndexer.java b/magik-squid/src/main/java/nl/ramsolutions/sw/magik/analysis/typing/indexer/MagikIndexer.java index e3ea207b..6e6b3c55 100644 --- a/magik-squid/src/main/java/nl/ramsolutions/sw/magik/analysis/typing/indexer/MagikIndexer.java +++ b/magik-squid/src/main/java/nl/ramsolutions/sw/magik/analysis/typing/indexer/MagikIndexer.java @@ -264,7 +264,7 @@ private void handleDefinition(final MagikFile magikFile, final SlottedExemplarDe // Slots. final TypeDocParser docParser = new TypeDocParser(node); final Map slotTypes = docParser.getSlotTypes(); - // This needs a default value ("") due to https://bugs.openjdk.java.net/browse/JDK-8148463 + // This needs a default value (TypeString.UNDEFINED) due to https://bugs.openjdk.java.net/browse/JDK-8148463 final Map slots = definition.getSlots().stream() .map(SlottedExemplarDefinition.Slot::getName) .collect(Collectors.toMap( diff --git a/magik-squid/src/main/java/nl/ramsolutions/sw/magik/analysis/typing/types/MagikTypeInstance.java b/magik-squid/src/main/java/nl/ramsolutions/sw/magik/analysis/typing/types/MagikTypeInstance.java index 140befb2..2fcd2435 100644 --- a/magik-squid/src/main/java/nl/ramsolutions/sw/magik/analysis/typing/types/MagikTypeInstance.java +++ b/magik-squid/src/main/java/nl/ramsolutions/sw/magik/analysis/typing/types/MagikTypeInstance.java @@ -10,6 +10,7 @@ import java.util.stream.Collectors; import javax.annotation.CheckForNull; import nl.ramsolutions.sw.magik.analysis.typing.ITypeKeeper; +import nl.ramsolutions.sw.magik.api.TypeStringGrammar; /** * MagikType for which Generics are filled. @@ -220,19 +221,24 @@ public String toString() { (a, b) -> a, LinkedHashMap::new)); // We want order! - final String genericsStr = generics.entrySet().stream() - .map(entry -> { - final GenericDeclaration genericDecl = entry.getKey(); - final GenericDefinition genericDef = entry.getValue(); - if (genericDef == null) { - return genericDecl.getTypeString().getFullString(); - } - - return genericDef.getTypeString().getFullString(); - }) - .collect(Collectors.joining(",")); + final String genericsStr = !generics.isEmpty() + ? generics.entrySet().stream() + .map(entry -> { + final GenericDeclaration genericDecl = entry.getKey(); + final GenericDefinition genericDef = entry.getValue(); + if (genericDef == null) { + return genericDecl.getTypeString().getFullString(); + } + + return genericDef.getTypeString().getFullString(); + }) + .collect(Collectors.joining( + TypeStringGrammar.Punctuator.TYPE_GENERIC_SEPARATOR.getValue(), + TypeStringGrammar.Punctuator.TYPE_GENERIC_OPEN.getValue(), + TypeStringGrammar.Punctuator.TYPE_GENERIC_CLOSE.getValue())) + : ""; return String.format( - "%s@%s(%s<%s>)", + "%s@%s(%s%s)", this.getClass().getName(), Integer.toHexString(this.hashCode()), this.getFullName(), genericsStr); } diff --git a/magik-squid/src/main/java/nl/ramsolutions/sw/magik/analysis/typing/types/TypeString.java b/magik-squid/src/main/java/nl/ramsolutions/sw/magik/analysis/typing/types/TypeString.java index f0dca2b8..fd41e9a5 100644 --- a/magik-squid/src/main/java/nl/ramsolutions/sw/magik/analysis/typing/types/TypeString.java +++ b/magik-squid/src/main/java/nl/ramsolutions/sw/magik/analysis/typing/types/TypeString.java @@ -26,6 +26,9 @@ public final class TypeString { @SuppressWarnings("checkstyle:JavadocVariable") public static final TypeString SELF = new TypeString(SelfType.SERIALIZED_NAME, DEFAULT_PACKAGE); + private static final String GENERIC = "_generic"; + private static final String PARAMETER = "_parameter"; + private final String string; private final String currentPackage; private final List combinedTypes; @@ -73,7 +76,7 @@ private TypeString(final String currentPackage, final TypeString... combinations * @return {@link TypeString}. */ public static TypeString ofGeneric(final String identifier) { - return new TypeString(identifier, "_generic"); + return new TypeString(identifier, TypeString.GENERIC); } /** @@ -82,7 +85,7 @@ public static TypeString ofGeneric(final String identifier) { * @return {@link TypeString}. */ public static TypeString ofParameterRef(final String identifier) { - return new TypeString(identifier, "_parameter"); + return new TypeString(identifier, PARAMETER); } /** @@ -170,11 +173,20 @@ public String getFullString() { return this.string; } + final String genericDefs = !this.generics.isEmpty() + ? this.generics.stream() + .map(TypeString::getFullString) + .collect(Collectors.joining( + TypeStringGrammar.Punctuator.TYPE_GENERIC_SEPARATOR.getValue(), + TypeStringGrammar.Punctuator.TYPE_GENERIC_OPEN.getValue(), + TypeStringGrammar.Punctuator.TYPE_GENERIC_CLOSE.getValue())) + : ""; + if (this.string.contains(":")) { - return this.string; + return this.string + genericDefs; } - return this.currentPackage + ":" + this.string; + return this.currentPackage + ":" + this.string + genericDefs; } /** @@ -266,6 +278,14 @@ public TypeString substituteType(final TypeString from, final TypeString to) { return to; } + if (this.isCombined()) { + final TypeString[] combinedSubstitutedArr = this.combinedTypes.stream() + .map(typeString -> typeString.substituteType(from, to)) + .collect(Collectors.toList()) + .toArray(TypeString[]::new); + return TypeString.ofCombination(this.currentPackage, combinedSubstitutedArr); + } + return this; }