Skip to content

Commit 4fc570c

Browse files
committed
Fixing resolve issue where references were not correctly resolved due to both module and class being returned from import statements.
1 parent b7bc82a commit 4fc570c

File tree

2 files changed

+37
-21
lines changed

2 files changed

+37
-21
lines changed

src/main/java/com/intellij/plugins/haxe/ide/annotator/semantics/HaxeReturnStatementAnnotator.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -218,12 +218,14 @@ private static boolean hasReturnPathsCovered(@Nullable PsiElement child) {
218218
}else {
219219
// check if we got cases with capture variables that cover remaining cases.
220220
List<HaxeSwitchCaseExpr> switchCaseExprList = haxeSwitchCase.getSwitchCaseExprList();
221-
HaxeSwitchCaseExpr first = switchCaseExprList.getFirst();
222-
PsiElement firstChild = first.getFirstChild();
223-
if (firstChild instanceof HaxeEnumExtractedValue) {
224-
hasDefault = true;
225-
}else if (firstChild instanceof HaxeSwitchCaseCaptureVar) {
226-
hasDefault = true;
221+
if(!switchCaseExprList.isEmpty()) {
222+
HaxeSwitchCaseExpr first = switchCaseExprList.getFirst();
223+
PsiElement firstChild = first.getFirstChild();
224+
if (firstChild instanceof HaxeEnumExtractedValue) {
225+
hasDefault = true;
226+
} else if (firstChild instanceof HaxeSwitchCaseCaptureVar) {
227+
hasDefault = true;
228+
}
227229
}
228230
}
229231
HaxeSwitchCaseBlock switchCaseBlock = haxeSwitchCase.getSwitchCaseBlock();

src/main/java/com/intellij/plugins/haxe/util/HaxeResolveUtil.java

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)