Deparentesize expression in ConstantExpressionEvaluator

This commit is contained in:
Natalia Ukhorskaya
2013-11-08 16:20:01 +04:00
parent 210899af22
commit b7b957ffd2
5 changed files with 49 additions and 4 deletions
@@ -39,7 +39,6 @@ import java.util.List;
import java.util.Map;
import static org.jetbrains.jet.lang.resolve.BindingContext.COMPILE_TIME_INITIALIZER;
import static org.jetbrains.jet.lang.resolve.BindingContext.RESOLVED_CALL;
@SuppressWarnings("StaticMethodReferencedViaSubclass")
public class ConstantExpressionEvaluator extends JetVisitor<CompileTimeConstant<?>, Void> {
@@ -58,9 +57,29 @@ public class ConstantExpressionEvaluator extends JetVisitor<CompileTimeConstant<
@Override
public CompileTimeConstant<?> visitParenthesizedExpression(@NotNull JetParenthesizedExpression expression, Void nothing) {
JetExpression innerExpression = expression.getExpression();
if (innerExpression == null) return null;
return innerExpression.accept(this, null);
JetExpression deparenthesizedExpression = getDeparenthesizedExpression(expression, nothing);
if (deparenthesizedExpression != null) {
return deparenthesizedExpression.accept(this, nothing);
}
return super.visitParenthesizedExpression(expression, nothing);
}
@Override
public CompileTimeConstant<?> visitPrefixExpression(@NotNull JetPrefixExpression expression, Void data) {
JetExpression deparenthesizedExpression = getDeparenthesizedExpression(expression, data);
if (deparenthesizedExpression != null) {
return deparenthesizedExpression.accept(this, data);
}
return super.visitPrefixExpression(expression, data);
}
@Nullable
private JetExpression getDeparenthesizedExpression(JetExpression expression, Void data) {
JetExpression deparenthesizedExpr = JetPsiUtil.deparenthesize(expression);
if (deparenthesizedExpr == expression) {
return null;
}
return deparenthesizedExpr;
}
@Override
@@ -69,3 +69,5 @@ public fun resolveCallToCompileTimeValue(
return null
}