From 2c4793b1184dbb264c03716c004288948370692f Mon Sep 17 00:00:00 2001 From: m0rkeulv Date: Mon, 15 May 2023 15:40:53 +0200 Subject: [PATCH] fixing resolver bug --- .../lang/psi/HaxeGenericSpecialization.java | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/intellij/plugins/haxe/lang/psi/HaxeGenericSpecialization.java b/src/main/java/com/intellij/plugins/haxe/lang/psi/HaxeGenericSpecialization.java index c1c25fd1e..57e379811 100644 --- a/src/main/java/com/intellij/plugins/haxe/lang/psi/HaxeGenericSpecialization.java +++ b/src/main/java/com/intellij/plugins/haxe/lang/psi/HaxeGenericSpecialization.java @@ -26,7 +26,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.Map; import java.util.Objects; @@ -42,22 +42,23 @@ public void put(PsiElement element, String genericName, HaxeClassResolveResult r } }; - final Map map; + // This must remain ordered, thus the LinkedHashMap. (HaxeGenericResolver relies on order it seems) + final LinkedHashMap map; public HaxeGenericSpecialization() { - this(new HashMap()); + this(new LinkedHashMap()); } @Override protected HaxeGenericSpecialization clone() { - final Map clonedMap = new HashMap(); + final LinkedHashMap clonedMap = new LinkedHashMap(); for (String key : map.keySet()) { clonedMap.put(key, map.get(key)); } return new HaxeGenericSpecialization(clonedMap); } - protected HaxeGenericSpecialization(Map map) { + protected HaxeGenericSpecialization(LinkedHashMap map) { this.map = map; } @@ -145,12 +146,12 @@ public HaxeClassResolveResult get(@Nullable PsiElement element, @NotNull String @NotNull public HaxeGenericSpecialization getInnerSpecialization(@Nullable PsiElement element) { - final Map result = getMapWithInnerSpecializations(element); + final LinkedHashMap result = getMapWithInnerSpecializations(element); return new HaxeGenericSpecialization(result); } @NotNull - private Map getMapWithInnerSpecializations(@Nullable PsiElement element) { + private LinkedHashMap getMapWithInnerSpecializations(@Nullable PsiElement element) { // We are no longer removing fully-qualified entries for the element. Rather, // we are duplicating them without the FQDN in the key so that pieces of the // code that do not have FQDN info can continue to match (which is what we @@ -158,7 +159,7 @@ private Map getMapWithInnerSpecializations(@Null // after an inner specialization is requested. final String prefixToRemove = getGenericKey(element, ""); - final Map result = new HashMap<>(); + final LinkedHashMap result = new LinkedHashMap<>(); for (String key : map.keySet()) { final HaxeClassResolveResult value = map.get(key); if (!prefixToRemove.isEmpty() && key.startsWith(prefixToRemove)) {