Deparentesize expression in ConstantExpressionEvaluator
This commit is contained in:
+23
-4
@@ -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]
|
||||
+10
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user