Skip to content

Commit

Permalink
Fixing another case of Types resolving to enum values (fields in abst…
Browse files Browse the repository at this point in the history
…ract enum)
  • Loading branch information
m0rkeulv committed Feb 4, 2024
1 parent 96d8f27 commit e0fdf19
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,10 @@ private List<? extends PsiElement> doResolveInner(@NotNull HaxeReference referen
if (fileModel != null) {
List<PsiElement> matchesInImport = HaxeResolveUtil.searchInImports(fileModel, referenceText);
// Remove enumValues if we are resolving typeTag as typeTags should not be EnumValues
// We also have to remove resolved fields as abstract enums is a thing
if (isType) {
matchesInImport = matchesInImport.stream().filter(element -> !(element instanceof HaxeEnumValueDeclaration)).toList();
matchesInImport = matchesInImport.stream().filter(element -> !(element instanceof HaxeFieldDeclaration)).toList();
}
if (!matchesInImport.isEmpty()) {
// one file may contain multiple enums and have enumValues with the same name; trying to match any argument list
Expand Down
21 changes: 19 additions & 2 deletions src/main/java/com/intellij/plugins/haxe/util/HaxeResolveUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ private static void addNotNullComponents(@NotNull List<HaxeNamedComponent> colle
*
* @param unique - whether multiple components sharing a name are included. If true, *which* of the components
* sharing a name is returned is indeterminate.
* @param resolver - map of generic type names to real types.
* @param parentResolver - map of generic type names to real types.
* @param rootHaxeClasses - which class(es) to gather components from.
* @return a list of named components defined in the rootHaxeClasses and their supertypes.
*/
Expand Down Expand Up @@ -364,7 +364,8 @@ public static List<HaxeNamedComponent> findNamedSubComponents(boolean unique, @N
List<HaxeType> baseTypes = new ArrayList<>();
baseTypes.addAll(haxeClass.getHaxeExtendsList());
baseTypes.addAll(haxeClass.getHaxeImplementsList());
List<HaxeClass> baseClasses = tryResolveClassesByQName(baseTypes);

List<HaxeClass> baseClasses = tryResolveClasses(baseTypes);
if (haxeClass.isEnum() && !haxeClass.isAbstractType() && haxeClass.getContext() != null) {
//Enums should provide the same methods as EnumValue
baseClasses.add(HaxeEnumValueUtil.getEnumValueClass(haxeClass.getContext()).getHaxeClass());
Expand Down Expand Up @@ -1043,6 +1044,22 @@ private static HaxeResolveResult tryResolveFunctionType(@Nullable HaxeFunctionTy
return tryResolveClassByTypeTag(returnType.getTypeOrAnonymous().getType(), specialization);
}

@NotNull
public static List<HaxeClass> tryResolveClasses(@NotNull List<HaxeType> types) {
final List<HaxeClass> result = new ArrayList<HaxeClass>();
for (HaxeType haxeType : types) {
PsiElement resolve = haxeType.getReferenceExpression().resolve();
if (resolve instanceof HaxeClass type) {
result.add(type);
}else {
final HaxeClass haxeClass = tryResolveClassByQName(haxeType);
if (haxeClass != null) {
result.add(haxeClass);
}
}
}
return result;
}
@NotNull
public static List<HaxeClass> tryResolveClassesByQName(@NotNull List<HaxeType> types) {
final List<HaxeClass> result = new ArrayList<HaxeClass>();
Expand Down

0 comments on commit e0fdf19

Please sign in to comment.