Skip to content

Commit

Permalink
fixing resolver bug
Browse files Browse the repository at this point in the history
  • Loading branch information
m0rkeulv committed May 15, 2023
1 parent 632b959 commit 2c4793b
Showing 1 changed file with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -42,22 +42,23 @@ public void put(PsiElement element, String genericName, HaxeClassResolveResult r
}
};

final Map<String, HaxeClassResolveResult> map;
// This must remain ordered, thus the LinkedHashMap. (HaxeGenericResolver relies on order it seems)
final LinkedHashMap<String, HaxeClassResolveResult> map;

public HaxeGenericSpecialization() {
this(new HashMap<String, HaxeClassResolveResult>());
this(new LinkedHashMap<String, HaxeClassResolveResult>());
}

@Override
protected HaxeGenericSpecialization clone() {
final Map<String, HaxeClassResolveResult> clonedMap = new HashMap<String, HaxeClassResolveResult>();
final LinkedHashMap<String, HaxeClassResolveResult> clonedMap = new LinkedHashMap<String, HaxeClassResolveResult>();
for (String key : map.keySet()) {
clonedMap.put(key, map.get(key));
}
return new HaxeGenericSpecialization(clonedMap);
}

protected HaxeGenericSpecialization(Map<String, HaxeClassResolveResult> map) {
protected HaxeGenericSpecialization(LinkedHashMap<String, HaxeClassResolveResult> map) {
this.map = map;
}

Expand Down Expand Up @@ -145,20 +146,20 @@ public HaxeClassResolveResult get(@Nullable PsiElement element, @NotNull String

@NotNull
public HaxeGenericSpecialization getInnerSpecialization(@Nullable PsiElement element) {
final Map<String, HaxeClassResolveResult> result = getMapWithInnerSpecializations(element);
final LinkedHashMap<String, HaxeClassResolveResult> result = getMapWithInnerSpecializations(element);
return new HaxeGenericSpecialization(result);
}

@NotNull
private Map<String, HaxeClassResolveResult> getMapWithInnerSpecializations(@Nullable PsiElement element) {
private LinkedHashMap<String, HaxeClassResolveResult> 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
// always did before). Now, newer code that always carries the FQDN can also match
// after an inner specialization is requested.

final String prefixToRemove = getGenericKey(element, "");
final Map<String, HaxeClassResolveResult> result = new HashMap<>();
final LinkedHashMap<String, HaxeClassResolveResult> result = new LinkedHashMap<>();
for (String key : map.keySet()) {
final HaxeClassResolveResult value = map.get(key);
if (!prefixToRemove.isEmpty() && key.startsWith(prefixToRemove)) {
Expand Down

0 comments on commit 2c4793b

Please sign in to comment.