From d9cf4ee732a8a7da31485ab74a5bec943f9795eb Mon Sep 17 00:00:00 2001 From: Toshiaki Kameyama Date: Sun, 13 Sep 2020 19:17:00 +0900 Subject: [PATCH] Add intention to evaluate compile time expression #KT-40251 Fixed --- .../after.kt.template | 1 + .../before.kt.template | 1 + .../description.html | 5 + .../messages/KotlinBundle.properties | 1 + idea/resources/META-INF/inspections.xml | 4 + .../EvaluateCompileTimeExpressionIntention.kt | 68 ++++++++++++++ .../evaluateCompileTimeExpression/.intention | 1 + .../evaluateCompileTimeExpression/boolean.kt | 2 + .../evaluateCompileTimeExpression/char.kt | 2 + .../char.kt.after | 2 + .../evaluateCompileTimeExpression/char2.kt | 2 + .../char2.kt.after | 2 + .../evaluateCompileTimeExpression/double.kt | 2 + .../double.kt.after | 2 + .../doubleNaN.kt | 2 + .../doubleNaN.kt.after | 2 + .../doubleNegativeInfinity.kt | 2 + .../doubleNegativeInfinity.kt.after | 2 + .../doublePositiveInfinity.kt | 2 + .../doublePositiveInfinity.kt.after | 2 + .../evaluateCompileTimeExpression/float.kt | 2 + .../float.kt.after | 2 + .../evaluateCompileTimeExpression/floatNaN.kt | 2 + .../floatNaN.kt.after | 2 + .../floatNegativeInfinity.kt | 2 + .../floatNegativeInfinity.kt.after | 2 + .../floatPositiveInfinity.kt | 2 + .../floatPositiveInfinity.kt.after | 2 + .../evaluateCompileTimeExpression/int.kt | 2 + .../int.kt.after | 2 + .../evaluateCompileTimeExpression/long.kt | 2 + .../long.kt.after | 2 + .../evaluateCompileTimeExpression/parens.kt | 2 + .../parens.kt.after | 2 + .../evaluateCompileTimeExpression/string.kt | 2 + .../evaluateCompileTimeExpression/variable.kt | 3 + .../intentions/IntentionTestGenerated.java | 93 +++++++++++++++++++ 37 files changed, 233 insertions(+) create mode 100644 idea/resources-en/intentionDescriptions/EvaluateCompileTimeExpressionIntention/after.kt.template create mode 100644 idea/resources-en/intentionDescriptions/EvaluateCompileTimeExpressionIntention/before.kt.template create mode 100644 idea/resources-en/intentionDescriptions/EvaluateCompileTimeExpressionIntention/description.html create mode 100644 idea/src/org/jetbrains/kotlin/idea/intentions/EvaluateCompileTimeExpressionIntention.kt create mode 100644 idea/testData/intentions/evaluateCompileTimeExpression/.intention create mode 100644 idea/testData/intentions/evaluateCompileTimeExpression/boolean.kt create mode 100644 idea/testData/intentions/evaluateCompileTimeExpression/char.kt create mode 100644 idea/testData/intentions/evaluateCompileTimeExpression/char.kt.after create mode 100644 idea/testData/intentions/evaluateCompileTimeExpression/char2.kt create mode 100644 idea/testData/intentions/evaluateCompileTimeExpression/char2.kt.after create mode 100644 idea/testData/intentions/evaluateCompileTimeExpression/double.kt create mode 100644 idea/testData/intentions/evaluateCompileTimeExpression/double.kt.after create mode 100644 idea/testData/intentions/evaluateCompileTimeExpression/doubleNaN.kt create mode 100644 idea/testData/intentions/evaluateCompileTimeExpression/doubleNaN.kt.after create mode 100644 idea/testData/intentions/evaluateCompileTimeExpression/doubleNegativeInfinity.kt create mode 100644 idea/testData/intentions/evaluateCompileTimeExpression/doubleNegativeInfinity.kt.after create mode 100644 idea/testData/intentions/evaluateCompileTimeExpression/doublePositiveInfinity.kt create mode 100644 idea/testData/intentions/evaluateCompileTimeExpression/doublePositiveInfinity.kt.after create mode 100644 idea/testData/intentions/evaluateCompileTimeExpression/float.kt create mode 100644 idea/testData/intentions/evaluateCompileTimeExpression/float.kt.after create mode 100644 idea/testData/intentions/evaluateCompileTimeExpression/floatNaN.kt create mode 100644 idea/testData/intentions/evaluateCompileTimeExpression/floatNaN.kt.after create mode 100644 idea/testData/intentions/evaluateCompileTimeExpression/floatNegativeInfinity.kt create mode 100644 idea/testData/intentions/evaluateCompileTimeExpression/floatNegativeInfinity.kt.after create mode 100644 idea/testData/intentions/evaluateCompileTimeExpression/floatPositiveInfinity.kt create mode 100644 idea/testData/intentions/evaluateCompileTimeExpression/floatPositiveInfinity.kt.after create mode 100644 idea/testData/intentions/evaluateCompileTimeExpression/int.kt create mode 100644 idea/testData/intentions/evaluateCompileTimeExpression/int.kt.after create mode 100644 idea/testData/intentions/evaluateCompileTimeExpression/long.kt create mode 100644 idea/testData/intentions/evaluateCompileTimeExpression/long.kt.after create mode 100644 idea/testData/intentions/evaluateCompileTimeExpression/parens.kt create mode 100644 idea/testData/intentions/evaluateCompileTimeExpression/parens.kt.after create mode 100644 idea/testData/intentions/evaluateCompileTimeExpression/string.kt create mode 100644 idea/testData/intentions/evaluateCompileTimeExpression/variable.kt diff --git a/idea/resources-en/intentionDescriptions/EvaluateCompileTimeExpressionIntention/after.kt.template b/idea/resources-en/intentionDescriptions/EvaluateCompileTimeExpressionIntention/after.kt.template new file mode 100644 index 00000000000..9dedd45165f --- /dev/null +++ b/idea/resources-en/intentionDescriptions/EvaluateCompileTimeExpressionIntention/after.kt.template @@ -0,0 +1 @@ +val x = 5 \ No newline at end of file diff --git a/idea/resources-en/intentionDescriptions/EvaluateCompileTimeExpressionIntention/before.kt.template b/idea/resources-en/intentionDescriptions/EvaluateCompileTimeExpressionIntention/before.kt.template new file mode 100644 index 00000000000..60ffe8d2c15 --- /dev/null +++ b/idea/resources-en/intentionDescriptions/EvaluateCompileTimeExpressionIntention/before.kt.template @@ -0,0 +1 @@ +val x = 2 + 3 \ No newline at end of file diff --git a/idea/resources-en/intentionDescriptions/EvaluateCompileTimeExpressionIntention/description.html b/idea/resources-en/intentionDescriptions/EvaluateCompileTimeExpressionIntention/description.html new file mode 100644 index 00000000000..91c4680d095 --- /dev/null +++ b/idea/resources-en/intentionDescriptions/EvaluateCompileTimeExpressionIntention/description.html @@ -0,0 +1,5 @@ + + +This intention replaces compile-time constant expression with its actual value. + + \ No newline at end of file diff --git a/idea/resources-en/messages/KotlinBundle.properties b/idea/resources-en/messages/KotlinBundle.properties index dc5601a7e7a..857b44bc863 100644 --- a/idea/resources-en/messages/KotlinBundle.properties +++ b/idea/resources-en/messages/KotlinBundle.properties @@ -2224,6 +2224,7 @@ inspection.redundant.nullable.return.type.display.name=Redundant nullable return 0.is.always.non.null.type=''{0}'' is always non-null type inspection.simplifiable.scope.function.display.name=Scope function with nested forEach can be simplified nested.1.call.in.0.could.be.simplified.to.2=Nested ''{1}'' call in ''{0}'' could be simplified to {2} +evaluate.compile.time.expression=Evaluate compile-time expression hints.title.codevision=Code Vision hints.title.codevision.show.hints.for=Show hints for: diff --git a/idea/resources/META-INF/inspections.xml b/idea/resources/META-INF/inspections.xml index b23e611b910..e59daa4ebb5 100644 --- a/idea/resources/META-INF/inspections.xml +++ b/idea/resources/META-INF/inspections.xml @@ -835,6 +835,10 @@ Kotlin + + org.jetbrains.kotlin.idea.intentions.EvaluateCompileTimeExpressionIntention + Kotlin + diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/EvaluateCompileTimeExpressionIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/EvaluateCompileTimeExpressionIntention.kt new file mode 100644 index 00000000000..d558159135f --- /dev/null +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/EvaluateCompileTimeExpressionIntention.kt @@ -0,0 +1,68 @@ +/* + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.idea.intentions + +import com.intellij.openapi.editor.Editor +import com.intellij.openapi.util.text.StringUtil +import org.jetbrains.kotlin.KtNodeTypes +import org.jetbrains.kotlin.idea.KotlinBundle +import org.jetbrains.kotlin.idea.caches.resolve.analyze +import org.jetbrains.kotlin.psi.* +import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType +import org.jetbrains.kotlin.resolve.calls.callUtil.getType +import org.jetbrains.kotlin.resolve.constants.evaluate.ConstantExpressionEvaluator +import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode + +class EvaluateCompileTimeExpressionIntention : SelfTargetingOffsetIndependentIntention( + KtBinaryExpression::class.java, + KotlinBundle.lazyMessage("evaluate.compile.time.expression") +) { + companion object { + val constantNodeTypes = listOf(KtNodeTypes.FLOAT_CONSTANT, KtNodeTypes.CHARACTER_CONSTANT, KtNodeTypes.INTEGER_CONSTANT) + } + + override fun isApplicableTo(element: KtBinaryExpression): Boolean { + if (element.getStrictParentOfType() != null || !element.isConstantExpression()) return false + val constantValue = element.getConstantValue() ?: return false + setTextGetter { KotlinBundle.message("replace.with.0", constantValue) } + return true + } + + override fun applyTo(element: KtBinaryExpression, editor: Editor?) { + val constantValue = element.getConstantValue() ?: return + element.replace(KtPsiFactory(element).createExpression(constantValue)) + } + + private fun KtExpression?.isConstantExpression(): Boolean { + return when (val expression = KtPsiUtil.deparenthesize(this)) { + is KtConstantExpression -> expression.elementType in constantNodeTypes + is KtPrefixExpression -> expression.baseExpression.isConstantExpression() + is KtBinaryExpression -> expression.left.isConstantExpression() && expression.right.isConstantExpression() + else -> false + } + } + + private fun KtBinaryExpression.getConstantValue(): String? { + val context = analyze(BodyResolveMode.PARTIAL) + val type = getType(context) ?: return null + val constantValue = ConstantExpressionEvaluator.getConstant(this, context)?.toConstantValue(type) ?: return null + return when (val value = constantValue.value) { + is Char -> "'${StringUtil.escapeStringCharacters(value.toString())}'" + is Long -> "${value}L" + is Float -> when { + value.isNaN() -> "Float.NaN" + value.isInfinite() -> if (value > 0.0f) "Float.POSITIVE_INFINITY" else "Float.NEGATIVE_INFINITY" + else -> "${value}f" + } + is Double -> when { + value.isNaN() -> "Double.NaN" + value.isInfinite() -> if (value > 0.0) "Double.POSITIVE_INFINITY" else "Double.NEGATIVE_INFINITY" + else -> value.toString() + } + else -> value.toString() + } + } +} diff --git a/idea/testData/intentions/evaluateCompileTimeExpression/.intention b/idea/testData/intentions/evaluateCompileTimeExpression/.intention new file mode 100644 index 00000000000..36828325936 --- /dev/null +++ b/idea/testData/intentions/evaluateCompileTimeExpression/.intention @@ -0,0 +1 @@ +org.jetbrains.kotlin.idea.intentions.EvaluateCompileTimeExpressionIntention diff --git a/idea/testData/intentions/evaluateCompileTimeExpression/boolean.kt b/idea/testData/intentions/evaluateCompileTimeExpression/boolean.kt new file mode 100644 index 00000000000..1fa713f7183 --- /dev/null +++ b/idea/testData/intentions/evaluateCompileTimeExpression/boolean.kt @@ -0,0 +1,2 @@ +// IS_APPLICABLE: false +val x = true && false \ No newline at end of file diff --git a/idea/testData/intentions/evaluateCompileTimeExpression/char.kt b/idea/testData/intentions/evaluateCompileTimeExpression/char.kt new file mode 100644 index 00000000000..b27609a947d --- /dev/null +++ b/idea/testData/intentions/evaluateCompileTimeExpression/char.kt @@ -0,0 +1,2 @@ +// INTENTION_TEXT: "Replace with ''b''" +val x = 'a' + 1 \ No newline at end of file diff --git a/idea/testData/intentions/evaluateCompileTimeExpression/char.kt.after b/idea/testData/intentions/evaluateCompileTimeExpression/char.kt.after new file mode 100644 index 00000000000..722a50d5595 --- /dev/null +++ b/idea/testData/intentions/evaluateCompileTimeExpression/char.kt.after @@ -0,0 +1,2 @@ +// INTENTION_TEXT: "Replace with ''b''" +val x = 'b' \ No newline at end of file diff --git a/idea/testData/intentions/evaluateCompileTimeExpression/char2.kt b/idea/testData/intentions/evaluateCompileTimeExpression/char2.kt new file mode 100644 index 00000000000..a80e54a3ca3 --- /dev/null +++ b/idea/testData/intentions/evaluateCompileTimeExpression/char2.kt @@ -0,0 +1,2 @@ +// INTENTION_TEXT: "Replace with ''\n''" +val x = '\t' + 1 \ No newline at end of file diff --git a/idea/testData/intentions/evaluateCompileTimeExpression/char2.kt.after b/idea/testData/intentions/evaluateCompileTimeExpression/char2.kt.after new file mode 100644 index 00000000000..ebbf9817222 --- /dev/null +++ b/idea/testData/intentions/evaluateCompileTimeExpression/char2.kt.after @@ -0,0 +1,2 @@ +// INTENTION_TEXT: "Replace with ''\n''" +val x = '\n' \ No newline at end of file diff --git a/idea/testData/intentions/evaluateCompileTimeExpression/double.kt b/idea/testData/intentions/evaluateCompileTimeExpression/double.kt new file mode 100644 index 00000000000..ad6cbef42e7 --- /dev/null +++ b/idea/testData/intentions/evaluateCompileTimeExpression/double.kt @@ -0,0 +1,2 @@ +// INTENTION_TEXT: "Replace with '3.0'" +val x = 1.0 + 2.0 \ No newline at end of file diff --git a/idea/testData/intentions/evaluateCompileTimeExpression/double.kt.after b/idea/testData/intentions/evaluateCompileTimeExpression/double.kt.after new file mode 100644 index 00000000000..1513af9ca31 --- /dev/null +++ b/idea/testData/intentions/evaluateCompileTimeExpression/double.kt.after @@ -0,0 +1,2 @@ +// INTENTION_TEXT: "Replace with '3.0'" +val x = 3.0 \ No newline at end of file diff --git a/idea/testData/intentions/evaluateCompileTimeExpression/doubleNaN.kt b/idea/testData/intentions/evaluateCompileTimeExpression/doubleNaN.kt new file mode 100644 index 00000000000..ab9cdf9f096 --- /dev/null +++ b/idea/testData/intentions/evaluateCompileTimeExpression/doubleNaN.kt @@ -0,0 +1,2 @@ +// INTENTION_TEXT: "Replace with 'Double.NaN'" +val x = 0.0 / 0.0 \ No newline at end of file diff --git a/idea/testData/intentions/evaluateCompileTimeExpression/doubleNaN.kt.after b/idea/testData/intentions/evaluateCompileTimeExpression/doubleNaN.kt.after new file mode 100644 index 00000000000..4ec99c12278 --- /dev/null +++ b/idea/testData/intentions/evaluateCompileTimeExpression/doubleNaN.kt.after @@ -0,0 +1,2 @@ +// INTENTION_TEXT: "Replace with 'Double.NaN'" +val x = Double.NaN \ No newline at end of file diff --git a/idea/testData/intentions/evaluateCompileTimeExpression/doubleNegativeInfinity.kt b/idea/testData/intentions/evaluateCompileTimeExpression/doubleNegativeInfinity.kt new file mode 100644 index 00000000000..3dfc494a0ce --- /dev/null +++ b/idea/testData/intentions/evaluateCompileTimeExpression/doubleNegativeInfinity.kt @@ -0,0 +1,2 @@ +// INTENTION_TEXT: "Replace with 'Double.NEGATIVE_INFINITY'" +val x = -1.0 / 0.0 \ No newline at end of file diff --git a/idea/testData/intentions/evaluateCompileTimeExpression/doubleNegativeInfinity.kt.after b/idea/testData/intentions/evaluateCompileTimeExpression/doubleNegativeInfinity.kt.after new file mode 100644 index 00000000000..c45a420835b --- /dev/null +++ b/idea/testData/intentions/evaluateCompileTimeExpression/doubleNegativeInfinity.kt.after @@ -0,0 +1,2 @@ +// INTENTION_TEXT: "Replace with 'Double.NEGATIVE_INFINITY'" +val x = Double.NEGATIVE_INFINITY \ No newline at end of file diff --git a/idea/testData/intentions/evaluateCompileTimeExpression/doublePositiveInfinity.kt b/idea/testData/intentions/evaluateCompileTimeExpression/doublePositiveInfinity.kt new file mode 100644 index 00000000000..62e90436467 --- /dev/null +++ b/idea/testData/intentions/evaluateCompileTimeExpression/doublePositiveInfinity.kt @@ -0,0 +1,2 @@ +// INTENTION_TEXT: "Replace with 'Double.POSITIVE_INFINITY'" +val x = 1.0 / 0.0 \ No newline at end of file diff --git a/idea/testData/intentions/evaluateCompileTimeExpression/doublePositiveInfinity.kt.after b/idea/testData/intentions/evaluateCompileTimeExpression/doublePositiveInfinity.kt.after new file mode 100644 index 00000000000..b40db8073ab --- /dev/null +++ b/idea/testData/intentions/evaluateCompileTimeExpression/doublePositiveInfinity.kt.after @@ -0,0 +1,2 @@ +// INTENTION_TEXT: "Replace with 'Double.POSITIVE_INFINITY'" +val x = Double.POSITIVE_INFINITY \ No newline at end of file diff --git a/idea/testData/intentions/evaluateCompileTimeExpression/float.kt b/idea/testData/intentions/evaluateCompileTimeExpression/float.kt new file mode 100644 index 00000000000..8879d7a149f --- /dev/null +++ b/idea/testData/intentions/evaluateCompileTimeExpression/float.kt @@ -0,0 +1,2 @@ +// INTENTION_TEXT: "Replace with '3.0f'" +val x = 1.0f + 2.0f \ No newline at end of file diff --git a/idea/testData/intentions/evaluateCompileTimeExpression/float.kt.after b/idea/testData/intentions/evaluateCompileTimeExpression/float.kt.after new file mode 100644 index 00000000000..44c74c75e6b --- /dev/null +++ b/idea/testData/intentions/evaluateCompileTimeExpression/float.kt.after @@ -0,0 +1,2 @@ +// INTENTION_TEXT: "Replace with '3.0f'" +val x = 3.0f \ No newline at end of file diff --git a/idea/testData/intentions/evaluateCompileTimeExpression/floatNaN.kt b/idea/testData/intentions/evaluateCompileTimeExpression/floatNaN.kt new file mode 100644 index 00000000000..6fd819ae62c --- /dev/null +++ b/idea/testData/intentions/evaluateCompileTimeExpression/floatNaN.kt @@ -0,0 +1,2 @@ +// INTENTION_TEXT: "Replace with 'Float.NaN'" +val x = 0.0f / 0.0f \ No newline at end of file diff --git a/idea/testData/intentions/evaluateCompileTimeExpression/floatNaN.kt.after b/idea/testData/intentions/evaluateCompileTimeExpression/floatNaN.kt.after new file mode 100644 index 00000000000..f67aa57d6c1 --- /dev/null +++ b/idea/testData/intentions/evaluateCompileTimeExpression/floatNaN.kt.after @@ -0,0 +1,2 @@ +// INTENTION_TEXT: "Replace with 'Float.NaN'" +val x = Float.NaN \ No newline at end of file diff --git a/idea/testData/intentions/evaluateCompileTimeExpression/floatNegativeInfinity.kt b/idea/testData/intentions/evaluateCompileTimeExpression/floatNegativeInfinity.kt new file mode 100644 index 00000000000..f9edfcdea1d --- /dev/null +++ b/idea/testData/intentions/evaluateCompileTimeExpression/floatNegativeInfinity.kt @@ -0,0 +1,2 @@ +// INTENTION_TEXT: "Replace with 'Float.NEGATIVE_INFINITY'" +val x = -1.0f / 0.0f \ No newline at end of file diff --git a/idea/testData/intentions/evaluateCompileTimeExpression/floatNegativeInfinity.kt.after b/idea/testData/intentions/evaluateCompileTimeExpression/floatNegativeInfinity.kt.after new file mode 100644 index 00000000000..b6ced096feb --- /dev/null +++ b/idea/testData/intentions/evaluateCompileTimeExpression/floatNegativeInfinity.kt.after @@ -0,0 +1,2 @@ +// INTENTION_TEXT: "Replace with 'Float.NEGATIVE_INFINITY'" +val x = Float.NEGATIVE_INFINITY \ No newline at end of file diff --git a/idea/testData/intentions/evaluateCompileTimeExpression/floatPositiveInfinity.kt b/idea/testData/intentions/evaluateCompileTimeExpression/floatPositiveInfinity.kt new file mode 100644 index 00000000000..c963127e07a --- /dev/null +++ b/idea/testData/intentions/evaluateCompileTimeExpression/floatPositiveInfinity.kt @@ -0,0 +1,2 @@ +// INTENTION_TEXT: "Replace with 'Float.POSITIVE_INFINITY'" +val x = 1.0f / 0.0f \ No newline at end of file diff --git a/idea/testData/intentions/evaluateCompileTimeExpression/floatPositiveInfinity.kt.after b/idea/testData/intentions/evaluateCompileTimeExpression/floatPositiveInfinity.kt.after new file mode 100644 index 00000000000..58ceb54e148 --- /dev/null +++ b/idea/testData/intentions/evaluateCompileTimeExpression/floatPositiveInfinity.kt.after @@ -0,0 +1,2 @@ +// INTENTION_TEXT: "Replace with 'Float.POSITIVE_INFINITY'" +val x = Float.POSITIVE_INFINITY \ No newline at end of file diff --git a/idea/testData/intentions/evaluateCompileTimeExpression/int.kt b/idea/testData/intentions/evaluateCompileTimeExpression/int.kt new file mode 100644 index 00000000000..f8135efa67b --- /dev/null +++ b/idea/testData/intentions/evaluateCompileTimeExpression/int.kt @@ -0,0 +1,2 @@ +// INTENTION_TEXT: "Replace with '5'" +val x = 2 + 3 \ No newline at end of file diff --git a/idea/testData/intentions/evaluateCompileTimeExpression/int.kt.after b/idea/testData/intentions/evaluateCompileTimeExpression/int.kt.after new file mode 100644 index 00000000000..e32c24208fe --- /dev/null +++ b/idea/testData/intentions/evaluateCompileTimeExpression/int.kt.after @@ -0,0 +1,2 @@ +// INTENTION_TEXT: "Replace with '5'" +val x = 5 \ No newline at end of file diff --git a/idea/testData/intentions/evaluateCompileTimeExpression/long.kt b/idea/testData/intentions/evaluateCompileTimeExpression/long.kt new file mode 100644 index 00000000000..8c115058837 --- /dev/null +++ b/idea/testData/intentions/evaluateCompileTimeExpression/long.kt @@ -0,0 +1,2 @@ +// INTENTION_TEXT: "Replace with '5L'" +val x = 2L + 3L \ No newline at end of file diff --git a/idea/testData/intentions/evaluateCompileTimeExpression/long.kt.after b/idea/testData/intentions/evaluateCompileTimeExpression/long.kt.after new file mode 100644 index 00000000000..05aede4db18 --- /dev/null +++ b/idea/testData/intentions/evaluateCompileTimeExpression/long.kt.after @@ -0,0 +1,2 @@ +// INTENTION_TEXT: "Replace with '5L'" +val x = 5L \ No newline at end of file diff --git a/idea/testData/intentions/evaluateCompileTimeExpression/parens.kt b/idea/testData/intentions/evaluateCompileTimeExpression/parens.kt new file mode 100644 index 00000000000..8052f76eb04 --- /dev/null +++ b/idea/testData/intentions/evaluateCompileTimeExpression/parens.kt @@ -0,0 +1,2 @@ +// INTENTION_TEXT: "Replace with '14'" +val x = ((1 + 2) * (-3 + 4)) + (5 + 6) \ No newline at end of file diff --git a/idea/testData/intentions/evaluateCompileTimeExpression/parens.kt.after b/idea/testData/intentions/evaluateCompileTimeExpression/parens.kt.after new file mode 100644 index 00000000000..ceb9bbcedba --- /dev/null +++ b/idea/testData/intentions/evaluateCompileTimeExpression/parens.kt.after @@ -0,0 +1,2 @@ +// INTENTION_TEXT: "Replace with '14'" +val x = 14 \ No newline at end of file diff --git a/idea/testData/intentions/evaluateCompileTimeExpression/string.kt b/idea/testData/intentions/evaluateCompileTimeExpression/string.kt new file mode 100644 index 00000000000..77ea8f369cc --- /dev/null +++ b/idea/testData/intentions/evaluateCompileTimeExpression/string.kt @@ -0,0 +1,2 @@ +// IS_APPLICABLE: false +val x = "a" + "b" \ No newline at end of file diff --git a/idea/testData/intentions/evaluateCompileTimeExpression/variable.kt b/idea/testData/intentions/evaluateCompileTimeExpression/variable.kt new file mode 100644 index 00000000000..8fbe1c0393d --- /dev/null +++ b/idea/testData/intentions/evaluateCompileTimeExpression/variable.kt @@ -0,0 +1,3 @@ +// IS_APPLICABLE: false +val i = 3 +val x = 2 + i diff --git a/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java index f8571978745..91e9e9f7060 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java @@ -8804,6 +8804,99 @@ public class IntentionTestGenerated extends AbstractIntentionTest { } } + @TestMetadata("idea/testData/intentions/evaluateCompileTimeExpression") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class EvaluateCompileTimeExpression extends AbstractIntentionTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); + } + + public void testAllFilesPresentInEvaluateCompileTimeExpression() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("idea/testData/intentions/evaluateCompileTimeExpression"), Pattern.compile("^([\\w\\-_]+)\\.(kt|kts)$"), null, true); + } + + @TestMetadata("boolean.kt") + public void testBoolean() throws Exception { + runTest("idea/testData/intentions/evaluateCompileTimeExpression/boolean.kt"); + } + + @TestMetadata("char.kt") + public void testChar() throws Exception { + runTest("idea/testData/intentions/evaluateCompileTimeExpression/char.kt"); + } + + @TestMetadata("char2.kt") + public void testChar2() throws Exception { + runTest("idea/testData/intentions/evaluateCompileTimeExpression/char2.kt"); + } + + @TestMetadata("double.kt") + public void testDouble() throws Exception { + runTest("idea/testData/intentions/evaluateCompileTimeExpression/double.kt"); + } + + @TestMetadata("doubleNaN.kt") + public void testDoubleNaN() throws Exception { + runTest("idea/testData/intentions/evaluateCompileTimeExpression/doubleNaN.kt"); + } + + @TestMetadata("doubleNegativeInfinity.kt") + public void testDoubleNegativeInfinity() throws Exception { + runTest("idea/testData/intentions/evaluateCompileTimeExpression/doubleNegativeInfinity.kt"); + } + + @TestMetadata("doublePositiveInfinity.kt") + public void testDoublePositiveInfinity() throws Exception { + runTest("idea/testData/intentions/evaluateCompileTimeExpression/doublePositiveInfinity.kt"); + } + + @TestMetadata("float.kt") + public void testFloat() throws Exception { + runTest("idea/testData/intentions/evaluateCompileTimeExpression/float.kt"); + } + + @TestMetadata("floatNaN.kt") + public void testFloatNaN() throws Exception { + runTest("idea/testData/intentions/evaluateCompileTimeExpression/floatNaN.kt"); + } + + @TestMetadata("floatNegativeInfinity.kt") + public void testFloatNegativeInfinity() throws Exception { + runTest("idea/testData/intentions/evaluateCompileTimeExpression/floatNegativeInfinity.kt"); + } + + @TestMetadata("floatPositiveInfinity.kt") + public void testFloatPositiveInfinity() throws Exception { + runTest("idea/testData/intentions/evaluateCompileTimeExpression/floatPositiveInfinity.kt"); + } + + @TestMetadata("int.kt") + public void testInt() throws Exception { + runTest("idea/testData/intentions/evaluateCompileTimeExpression/int.kt"); + } + + @TestMetadata("long.kt") + public void testLong() throws Exception { + runTest("idea/testData/intentions/evaluateCompileTimeExpression/long.kt"); + } + + @TestMetadata("parens.kt") + public void testParens() throws Exception { + runTest("idea/testData/intentions/evaluateCompileTimeExpression/parens.kt"); + } + + @TestMetadata("string.kt") + public void testString() throws Exception { + runTest("idea/testData/intentions/evaluateCompileTimeExpression/string.kt"); + } + + @TestMetadata("variable.kt") + public void testVariable() throws Exception { + runTest("idea/testData/intentions/evaluateCompileTimeExpression/variable.kt"); + } + } + @TestMetadata("idea/testData/intentions/expandBooleanExpression") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class)