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
}
@@ -0,0 +1,7 @@
package test
annotation class Ann(i: Int)
Ann(@A 1) class MyClass
// EXPECTED: Ann[i = 1.toInt(): jet.Int]
@@ -0,0 +1,7 @@
package test
annotation class Ann(i: Int)
Ann((1 + 2) * 2) class MyClass
// EXPECTED: Ann[i = 6.toInt(): jet.Int]
@@ -143,6 +143,11 @@ public class AnnotationParameterTestGenerated extends AbstractAnnotationParamete
doTest("compiler/testData/resolveAnnotations/parameters/expressions/intrincics.kt");
}
@TestMetadata("labeled.kt")
public void testLabeled() throws Exception {
doTest("compiler/testData/resolveAnnotations/parameters/expressions/labeled.kt");
}
@TestMetadata("long.kt")
public void testLong() throws Exception {
doTest("compiler/testData/resolveAnnotations/parameters/expressions/long.kt");
@@ -198,6 +203,11 @@ public class AnnotationParameterTestGenerated extends AbstractAnnotationParamete
doTest("compiler/testData/resolveAnnotations/parameters/expressions/orOr.kt");
}
@TestMetadata("paranthesized.kt")
public void testParanthesized() throws Exception {
doTest("compiler/testData/resolveAnnotations/parameters/expressions/paranthesized.kt");
}
@TestMetadata("plus.kt")
public void testPlus() throws Exception {
doTest("compiler/testData/resolveAnnotations/parameters/expressions/plus.kt");