diff --git a/uast/uast-common/src/org/jetbrains/uast/evaluation/TreeBasedEvaluator.kt b/uast/uast-common/src/org/jetbrains/uast/evaluation/TreeBasedEvaluator.kt index 04dd6a017d5c..cd8da7a838cd 100644 --- a/uast/uast-common/src/org/jetbrains/uast/evaluation/TreeBasedEvaluator.kt +++ b/uast/uast-common/src/org/jetbrains/uast/evaluation/TreeBasedEvaluator.kt @@ -59,13 +59,20 @@ class TreeBasedEvaluator( return resultCache[expression]?.value } - override fun evaluate(expression: UExpression, state: UEvaluationState?): UValue { + override fun evaluate(expression: UExpression, state: UEvaluationState?): UValue = getEvaluationInfo(expression, state).value + + private fun getEvaluationInfo(expression: UExpression, state: UEvaluationState? = null): UEvaluationInfo { if (state == null) { val result = resultCache[expression] - if (result != null) return result.value + if (result != null) return result } val inputState = state ?: inputStateCache[expression] ?: expression.createEmptyState() - return expression.accept(this, inputState).value + return expression.accept(this, inputState) + } + + override fun evaluateVariableByReference(variableReference: UReferenceExpression, state: UEvaluationState?): UValue { + val target = variableReference.resolveToUElement() as? UVariable ?: return UUndeterminedValue + return getEvaluationInfo(variableReference, state).state[target] } // ----------------------- // diff --git a/uast/uast-common/src/org/jetbrains/uast/evaluation/UEvaluator.kt b/uast/uast-common/src/org/jetbrains/uast/evaluation/UEvaluator.kt index 037fe346c304..74238e40e5bf 100644 --- a/uast/uast-common/src/org/jetbrains/uast/evaluation/UEvaluator.kt +++ b/uast/uast-common/src/org/jetbrains/uast/evaluation/UEvaluator.kt @@ -43,6 +43,8 @@ interface UEvaluator { fun evaluate(expression: UExpression, state: UEvaluationState? = null): UValue + fun evaluateVariableByReference(variableReference: UReferenceExpression, state: UEvaluationState? = null): UValue + fun getDependents(dependency: UDependency): Set }