@@ -905,7 +905,7 @@ public static HaxeClass tryResolveClassByQName(@Nullable PsiElement element) {
905905 if (element == null || element .getContext () == null ) {
906906 return null ;
907907 }
908- String name = getQNameFromImportStatment (element );
908+ String name = getQNameFromImportStatement (element );
909909 PsiElement type = tryGetReferenceExpressionFromType (element );
910910 HaxeClass result = name == null ? tryResolveClassByQNameWhenGetQNameFail (type ) : findClassByQName (name , element .getContext ());
911911 result = result != null ? result : findClassByQNameInSuperPackages (type );
@@ -970,7 +970,7 @@ private static HaxeClass findClassByQNameInSuperPackages(PsiElement type) {
970970 }
971971
972972 @ Nullable
973- private static String getQNameFromImportStatment (@ NotNull PsiElement type ) {
973+ private static String getQNameFromImportStatement (@ NotNull PsiElement type ) {
974974 HaxeImportStatement importStatement = PsiTreeUtil .getParentOfType (type , HaxeImportStatement .class , false );
975975 if (importStatement != null ) {
976976 HaxeReferenceExpression referenceExpression = importStatement .getReferenceExpression ();
@@ -1018,20 +1018,34 @@ private static HaxeClass tryResolveClassByQNameWhenGetQNameFail(@NotNull PsiElem
10181018 .toList ();
10191019 }
10201020 // one file may contain multiple enums and have enumValues with the same name; trying to match any argument list
1021- if (matchesInImport .size () > 1 )
1022- if (type .getParent () instanceof HaxeCallExpression callExpression ) {
1023- int expectedSize = Optional .ofNullable (callExpression .getExpressionList ()).map (e -> e .getExpressionList ().size ()).orElse (0 );
1024- for (PsiElement element : matchesInImport ) {
1025- if (element instanceof HaxeEnumValueDeclarationConstructor enumValueDeclaration ) {
1026- int currentSize = Optional .of (enumValueDeclaration .getParameterList ()).map (p -> p .getParameterList ().size ()).orElse (0 );
1027- if (expectedSize == currentSize ) {
1028- result = element ;
1029- break ;
1030- }
1031- }
1032- }
1021+ if (matchesInImport .size () > 1 ) {
1022+ if (type .getParent () instanceof HaxeCallExpression callExpression ) {
1023+ int expectedSize = Optional .ofNullable (callExpression .getExpressionList ()).map (e -> e .getExpressionList ().size ()).orElse (0 );
1024+ for (PsiElement element : matchesInImport ) {
1025+ if (element instanceof HaxeEnumValueDeclarationConstructor enumValueDeclaration ) {
1026+ int currentSize = Optional .of (enumValueDeclaration .getParameterList ()).map (p -> p .getParameterList ().size ()).orElse (0 );
1027+ if (expectedSize == currentSize ) {
1028+ result = element ;
1029+ break ;
1030+ }
10331031 }
1034- if (result == null && !matchesInImport .isEmpty ()) result = matchesInImport .get (0 );
1032+ }
1033+ // we may also get multiple matches due to both module and class names can be the same,
1034+ // so we check if we are resolving a reference expression and check if the class contains
1035+ // the expected member
1036+ } else if (type .getParent () instanceof HaxeReferenceExpression reference ) {
1037+ String memberName = reference .getIdentifier ().getText ();
1038+ for (PsiElement element : matchesInImport ) {
1039+ if (element instanceof HaxeClass haxeClass ) {
1040+ HaxeClassModel model = haxeClass .getModel ();
1041+ if (model .getMember (memberName , null ) != null ) {
1042+ return haxeClass ;
1043+ }
1044+ }
1045+ }
1046+ }
1047+ }
1048+ if (result == null && !matchesInImport .isEmpty ()) result = matchesInImport .getFirst ();
10351049 }
10361050 }
10371051 if (result == null ) result = searchInSamePackage (fileModel , className , false , false );
0 commit comments