From 3fcfe641de0a3166e7c4d91bb66a0cb5c8f6c928 Mon Sep 17 00:00:00 2001 From: m0rkeulv Date: Sat, 19 Aug 2023 14:19:24 +0200 Subject: [PATCH] Fixing type resolve for inline method calls (#868) --- CHANGELOG.md | 4 ++ .../model/type/HaxeExpressionEvaluator.java | 3 ++ .../plugins/haxe/util/HaxeResolveUtil.java | 40 ++++++++++++++++++- 3 files changed, 46 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 304599cf3..6a7147689 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 1.4.13 +* Added: Quick fix for incorrect extends and implements (#940) +* Fixed: Resolving type from inline method calls (#868) + ## 1.4.12 * Bugfix: "import class quickfix" missing in some cases (#1132) * Bugfix: "Find Usages" was not checking catch blocks correctly(#929) diff --git a/src/main/java/com/intellij/plugins/haxe/model/type/HaxeExpressionEvaluator.java b/src/main/java/com/intellij/plugins/haxe/model/type/HaxeExpressionEvaluator.java index 2dafa4221..d9a18d57e 100644 --- a/src/main/java/com/intellij/plugins/haxe/model/type/HaxeExpressionEvaluator.java +++ b/src/main/java/com/intellij/plugins/haxe/model/type/HaxeExpressionEvaluator.java @@ -554,6 +554,9 @@ else if (element instanceof HaxeLocalVarDeclaration varDeclaration) { if (valueExpression.getVarInit() != null){ return handle(valueExpression.getVarInit(), context, resolver); } + if (valueExpression.getExpression() != null){ + return handle(valueExpression.getExpression(), context, resolver); + } } if (element instanceof HaxeReferenceExpression) { diff --git a/src/main/java/com/intellij/plugins/haxe/util/HaxeResolveUtil.java b/src/main/java/com/intellij/plugins/haxe/util/HaxeResolveUtil.java index d9e38e3fd..1b6cae10d 100644 --- a/src/main/java/com/intellij/plugins/haxe/util/HaxeResolveUtil.java +++ b/src/main/java/com/intellij/plugins/haxe/util/HaxeResolveUtil.java @@ -55,6 +55,7 @@ import java.util.stream.Stream; import static com.intellij.plugins.haxe.lang.lexer.HaxeTokenTypeSets.DOC_COMMENT; +import static com.intellij.plugins.haxe.model.type.HaxeExpressionEvaluator.evaluate; import static com.intellij.plugins.haxe.util.HaxeDebugLogUtil.traceAs; /** @@ -751,9 +752,46 @@ private static HaxeResolveResult getHaxeClassResolveResultInternal(@Nullable Psi result.specialize(initExpression); return result; } + + if (element instanceof HaxeValueExpression valueExpression) { + result = resolveValueExpressionClass(valueExpression, specialization); + if (result != null) { + return result; + } + } + return getHaxeClassResolveResult(initExpression, specialization); } + private static HaxeResolveResult resolveValueExpressionClass(HaxeValueExpression valueExpression, + @Nullable HaxeGenericSpecialization specialization) { + + HaxePsiCompositeElement element = null; + if (valueExpression.getSwitchStatement() != null) { + element = valueExpression.getSwitchStatement(); + } + if (valueExpression.getIfStatement() != null) { + element = valueExpression.getIfStatement(); + } + if (valueExpression.getTryStatement() != null) { + element = valueExpression.getTryStatement(); + } + if (valueExpression.getVarInit() != null) { + element = valueExpression.getVarInit(); + } + if (valueExpression.getExpression() != null) { + element = valueExpression.getExpression(); + + } + + HaxeExpressionEvaluatorContext context = new HaxeExpressionEvaluatorContext(element); + ResultHolder result = evaluate(element, context, specialization.toGenericResolver(valueExpression)).result; + if (result.getClassType() != null) { + return result.getClassType().asResolveResult(); + } + return null; + } + private static HaxeResolveResult searchForIterableTypeRecursively(HaxeResolveResult resolveResult, List circularReferenceProtection) { final HaxeClass resolveResultHaxeClass = resolveResult.getHaxeClass(); @@ -1247,7 +1285,7 @@ public static SpecificHaxeClassReference resolveExtractorEnum(HaxeEnumArgumentEx expression = parenthesizedExpression.getExpression(); } HaxeGenericResolver resolver = HaxeGenericResolverUtil.generateResolverFromScopeParents(expression); - ResultHolder result = HaxeExpressionEvaluator.evaluate(expression, new HaxeExpressionEvaluatorContext(expression), resolver).result; + ResultHolder result = evaluate(expression, new HaxeExpressionEvaluatorContext(expression), resolver).result; // null type "hack" : if nullType unwrap to real type if(result.getType().isNullType()) { result = result.getClassType().getSpecifics()[0];