From cf3215b96e5cb9270228e7ce6b6649a6e8982e29 Mon Sep 17 00:00:00 2001 From: Toshiaki Kameyama Date: Wed, 28 Nov 2018 06:13:30 +0300 Subject: [PATCH] Add quick fixes for SMARTCAST_IMPOSSIBLE in 'if' #KT-27184 Fixed --- .../IfThenToSafeAccessInspection.kt | 8 +- .../intentions/IfThenToElvisIntention.kt | 6 +- .../kotlin/idea/quickfix/QuickFixRegistrar.kt | 1 + .../SmartCastImpossibleInIfThenFactory.kt | 63 ++++++++++++++++ .../smartCastImpossibleInIfThen/ifThen.kt | 8 ++ .../ifThen.kt.after | 8 ++ .../smartCastImpossibleInIfThen/ifThen2.kt | 10 +++ .../ifThen2.kt.after | 8 ++ .../smartCastImpossibleInIfThen/ifThen3.kt | 11 +++ .../ifThen3.kt.after | 11 +++ .../smartCastImpossibleInIfThen/ifThen4.kt | 8 ++ .../ifThen4.kt.after | 8 ++ .../smartCastImpossibleInIfThen/ifThen5.kt | 11 +++ .../ifThen5.kt.after | 11 +++ .../smartCastImpossibleInIfThen/ifThenElse.kt | 8 ++ .../ifThenElse.kt.after | 8 ++ .../ifThenElse2.kt | 12 +++ .../ifThenElse2.kt.after | 8 ++ .../ifThenElse3.kt | 13 ++++ .../ifThenElse3.kt.after | 13 ++++ .../ifThenElse4.kt | 8 ++ .../ifThenElse4.kt.after | 8 ++ .../ifThenElse5.kt | 13 ++++ .../ifThenElse5.kt.after | 13 ++++ .../ifThenElseMultiStatement.kt | 18 +++++ .../ifThenMultiStatement.kt | 16 ++++ .../QuickFixMultiFileTestGenerated.java | 13 ++++ .../idea/quickfix/QuickFixTestGenerated.java | 73 +++++++++++++++++++ 28 files changed, 392 insertions(+), 4 deletions(-) create mode 100644 idea/src/org/jetbrains/kotlin/idea/quickfix/SmartCastImpossibleInIfThenFactory.kt create mode 100644 idea/testData/quickfix/smartCastImpossibleInIfThen/ifThen.kt create mode 100644 idea/testData/quickfix/smartCastImpossibleInIfThen/ifThen.kt.after create mode 100644 idea/testData/quickfix/smartCastImpossibleInIfThen/ifThen2.kt create mode 100644 idea/testData/quickfix/smartCastImpossibleInIfThen/ifThen2.kt.after create mode 100644 idea/testData/quickfix/smartCastImpossibleInIfThen/ifThen3.kt create mode 100644 idea/testData/quickfix/smartCastImpossibleInIfThen/ifThen3.kt.after create mode 100644 idea/testData/quickfix/smartCastImpossibleInIfThen/ifThen4.kt create mode 100644 idea/testData/quickfix/smartCastImpossibleInIfThen/ifThen4.kt.after create mode 100644 idea/testData/quickfix/smartCastImpossibleInIfThen/ifThen5.kt create mode 100644 idea/testData/quickfix/smartCastImpossibleInIfThen/ifThen5.kt.after create mode 100644 idea/testData/quickfix/smartCastImpossibleInIfThen/ifThenElse.kt create mode 100644 idea/testData/quickfix/smartCastImpossibleInIfThen/ifThenElse.kt.after create mode 100644 idea/testData/quickfix/smartCastImpossibleInIfThen/ifThenElse2.kt create mode 100644 idea/testData/quickfix/smartCastImpossibleInIfThen/ifThenElse2.kt.after create mode 100644 idea/testData/quickfix/smartCastImpossibleInIfThen/ifThenElse3.kt create mode 100644 idea/testData/quickfix/smartCastImpossibleInIfThen/ifThenElse3.kt.after create mode 100644 idea/testData/quickfix/smartCastImpossibleInIfThen/ifThenElse4.kt create mode 100644 idea/testData/quickfix/smartCastImpossibleInIfThen/ifThenElse4.kt.after create mode 100644 idea/testData/quickfix/smartCastImpossibleInIfThen/ifThenElse5.kt create mode 100644 idea/testData/quickfix/smartCastImpossibleInIfThen/ifThenElse5.kt.after create mode 100644 idea/testData/quickfix/smartCastImpossibleInIfThen/ifThenElseMultiStatement.kt create mode 100644 idea/testData/quickfix/smartCastImpossibleInIfThen/ifThenMultiStatement.kt diff --git a/idea/src/org/jetbrains/kotlin/idea/inspections/branchedTransformations/IfThenToSafeAccessInspection.kt b/idea/src/org/jetbrains/kotlin/idea/inspections/branchedTransformations/IfThenToSafeAccessInspection.kt index 00f640357b2..a1217e7f39a 100644 --- a/idea/src/org/jetbrains/kotlin/idea/inspections/branchedTransformations/IfThenToSafeAccessInspection.kt +++ b/idea/src/org/jetbrains/kotlin/idea/inspections/branchedTransformations/IfThenToSafeAccessInspection.kt @@ -32,11 +32,15 @@ import org.jetbrains.kotlin.psi.psiUtil.startOffset import org.jetbrains.kotlin.resolve.bindingContextUtil.isUsedAsExpression import org.jetbrains.kotlin.resolve.calls.callUtil.getType -class IfThenToSafeAccessInspection : AbstractApplicabilityBasedInspection(KtIfExpression::class.java) { +class IfThenToSafeAccessInspection( + private val stableElementNeeded: Boolean +) : AbstractApplicabilityBasedInspection(KtIfExpression::class.java) { + + constructor() : this(stableElementNeeded = true) override fun isApplicable(element: KtIfExpression): Boolean { val ifThenToSelectData = element.buildSelectTransformationData() ?: return false - if (!ifThenToSelectData.receiverExpression.isStableSimpleExpression(ifThenToSelectData.context)) return false + if (stableElementNeeded && !ifThenToSelectData.receiverExpression.isStableSimpleExpression(ifThenToSelectData.context)) return false return ifThenToSelectData.clausesReplaceableBySafeCall() } diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/IfThenToElvisIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/IfThenToElvisIntention.kt index 76404bd944d..14350d892bd 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/IfThenToElvisIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/IfThenToElvisIntention.kt @@ -42,11 +42,13 @@ class IfThenToElvisInspection : IntentionBasedInspection( if (element.shouldBeTransformed()) super.problemHighlightType(element) else ProblemHighlightType.INFORMATION } -class IfThenToElvisIntention : SelfTargetingOffsetIndependentIntention( +class IfThenToElvisIntention (private val stableElementNeeded: Boolean) : SelfTargetingOffsetIndependentIntention( KtIfExpression::class.java, "Replace 'if' expression with elvis expression" ) { + constructor() : this(stableElementNeeded = true) + private fun IfThenToSelectData.clausesReplaceableByElvis(): Boolean = when { baseClause == null || negatedClause == null || negatedClause.isNullOrBlockExpression() -> @@ -65,7 +67,7 @@ class IfThenToElvisIntention : SelfTargetingOffsetIndependentIntention { + val element = diagnostic.psiElement as? KtNameReferenceExpression ?: return emptyList() + val ifExpression = + element.getStrictParentOfType()?.parent as? KtIfExpression ?: return emptyList() + + val ifThenToSafeAccess = IfThenToSafeAccessInspection(stableElementNeeded = false) + val ifThenToElvis = IfThenToElvisIntention(stableElementNeeded = false) + + return listOf( + createQuickFix( + ifExpression, + { ifThenToSafeAccess.fixText(it) }, + { ifThenToSafeAccess.isApplicable(it) }, + { ifExpr, project, editor -> ifThenToSafeAccess.applyTo(ifExpr.ifKeyword, project, editor) } + ), + createQuickFix( + ifExpression, + { ifThenToElvis.text }, + { ifThenToElvis.isApplicableTo(it) }, + { ifExpr, _, editor -> ifThenToElvis.applyTo(ifExpr, editor) } + ) + ) + } + + private fun createQuickFix( + ifExpression: KtIfExpression, + fixText: (KtIfExpression) -> String, + isApplicable: (KtIfExpression) -> Boolean, + applyTo: (KtIfExpression, project: Project, editor: Editor?) -> Unit + ): KotlinQuickFixAction { + return object : KotlinQuickFixAction(ifExpression) { + override fun getText() = fixText(ifExpression) + + override fun getFamilyName() = text + + override fun isAvailable(project: Project, editor: Editor?, file: KtFile) = element?.let { isApplicable(it) } ?: false + + override fun invoke(project: Project, editor: Editor?, file: KtFile) { + element?.also { applyTo(it, project, editor) } + } + } + } +} \ No newline at end of file diff --git a/idea/testData/quickfix/smartCastImpossibleInIfThen/ifThen.kt b/idea/testData/quickfix/smartCastImpossibleInIfThen/ifThen.kt new file mode 100644 index 00000000000..94c52926907 --- /dev/null +++ b/idea/testData/quickfix/smartCastImpossibleInIfThen/ifThen.kt @@ -0,0 +1,8 @@ +// "Replace 'if' expression with safe access expression" "true" +class Test { + var x: String? = "" + + fun test() { + if (x != null) x.length + } +} \ No newline at end of file diff --git a/idea/testData/quickfix/smartCastImpossibleInIfThen/ifThen.kt.after b/idea/testData/quickfix/smartCastImpossibleInIfThen/ifThen.kt.after new file mode 100644 index 00000000000..6ba5c93ddfd --- /dev/null +++ b/idea/testData/quickfix/smartCastImpossibleInIfThen/ifThen.kt.after @@ -0,0 +1,8 @@ +// "Replace 'if' expression with safe access expression" "true" +class Test { + var x: String? = "" + + fun test() { + x?.length + } +} \ No newline at end of file diff --git a/idea/testData/quickfix/smartCastImpossibleInIfThen/ifThen2.kt b/idea/testData/quickfix/smartCastImpossibleInIfThen/ifThen2.kt new file mode 100644 index 00000000000..69554d34195 --- /dev/null +++ b/idea/testData/quickfix/smartCastImpossibleInIfThen/ifThen2.kt @@ -0,0 +1,10 @@ +// "Replace 'if' expression with safe access expression" "true" +class Test { + var x: String? = "" + + fun test() { + if (x != null) { + x.length + } + } +} \ No newline at end of file diff --git a/idea/testData/quickfix/smartCastImpossibleInIfThen/ifThen2.kt.after b/idea/testData/quickfix/smartCastImpossibleInIfThen/ifThen2.kt.after new file mode 100644 index 00000000000..6ba5c93ddfd --- /dev/null +++ b/idea/testData/quickfix/smartCastImpossibleInIfThen/ifThen2.kt.after @@ -0,0 +1,8 @@ +// "Replace 'if' expression with safe access expression" "true" +class Test { + var x: String? = "" + + fun test() { + x?.length + } +} \ No newline at end of file diff --git a/idea/testData/quickfix/smartCastImpossibleInIfThen/ifThen3.kt b/idea/testData/quickfix/smartCastImpossibleInIfThen/ifThen3.kt new file mode 100644 index 00000000000..8f6f0dbdf6b --- /dev/null +++ b/idea/testData/quickfix/smartCastImpossibleInIfThen/ifThen3.kt @@ -0,0 +1,11 @@ +// "Replace 'if' expression with safe access expression" "true" +// WITH_RUNTIME +class Test { + var x: String? = "" + + fun test() { + if (x != null) foo(x) + } + + fun foo(s: String) = 1 +} \ No newline at end of file diff --git a/idea/testData/quickfix/smartCastImpossibleInIfThen/ifThen3.kt.after b/idea/testData/quickfix/smartCastImpossibleInIfThen/ifThen3.kt.after new file mode 100644 index 00000000000..77df139a629 --- /dev/null +++ b/idea/testData/quickfix/smartCastImpossibleInIfThen/ifThen3.kt.after @@ -0,0 +1,11 @@ +// "Replace 'if' expression with safe access expression" "true" +// WITH_RUNTIME +class Test { + var x: String? = "" + + fun test() { + x?.let { foo(it) } + } + + fun foo(s: String) = 1 +} \ No newline at end of file diff --git a/idea/testData/quickfix/smartCastImpossibleInIfThen/ifThen4.kt b/idea/testData/quickfix/smartCastImpossibleInIfThen/ifThen4.kt new file mode 100644 index 00000000000..b7e743bc89b --- /dev/null +++ b/idea/testData/quickfix/smartCastImpossibleInIfThen/ifThen4.kt @@ -0,0 +1,8 @@ +// "Replace 'if' expression with safe access expression" "true" +class Test { + var x: Any? = null + + fun test() { + if (x is String) x.length + } +} \ No newline at end of file diff --git a/idea/testData/quickfix/smartCastImpossibleInIfThen/ifThen4.kt.after b/idea/testData/quickfix/smartCastImpossibleInIfThen/ifThen4.kt.after new file mode 100644 index 00000000000..1f7ac6cd30d --- /dev/null +++ b/idea/testData/quickfix/smartCastImpossibleInIfThen/ifThen4.kt.after @@ -0,0 +1,8 @@ +// "Replace 'if' expression with safe access expression" "true" +class Test { + var x: Any? = null + + fun test() { + (x as? String)?.length + } +} \ No newline at end of file diff --git a/idea/testData/quickfix/smartCastImpossibleInIfThen/ifThen5.kt b/idea/testData/quickfix/smartCastImpossibleInIfThen/ifThen5.kt new file mode 100644 index 00000000000..93848749932 --- /dev/null +++ b/idea/testData/quickfix/smartCastImpossibleInIfThen/ifThen5.kt @@ -0,0 +1,11 @@ +// "Replace 'if' expression with safe access expression" "true" +// WITH_RUNTIME +class Test { + var x: Any? = null + + fun test() { + if (x is String) foo(x) + } + + fun foo(s: String) = 1 +} \ No newline at end of file diff --git a/idea/testData/quickfix/smartCastImpossibleInIfThen/ifThen5.kt.after b/idea/testData/quickfix/smartCastImpossibleInIfThen/ifThen5.kt.after new file mode 100644 index 00000000000..3e00b05820e --- /dev/null +++ b/idea/testData/quickfix/smartCastImpossibleInIfThen/ifThen5.kt.after @@ -0,0 +1,11 @@ +// "Replace 'if' expression with safe access expression" "true" +// WITH_RUNTIME +class Test { + var x: Any? = null + + fun test() { + (x as? String)?.let { foo(it) } + } + + fun foo(s: String) = 1 +} \ No newline at end of file diff --git a/idea/testData/quickfix/smartCastImpossibleInIfThen/ifThenElse.kt b/idea/testData/quickfix/smartCastImpossibleInIfThen/ifThenElse.kt new file mode 100644 index 00000000000..5026d358c4a --- /dev/null +++ b/idea/testData/quickfix/smartCastImpossibleInIfThen/ifThenElse.kt @@ -0,0 +1,8 @@ +// "Replace 'if' expression with elvis expression" "true" +class Test { + var x: String? = "" + + fun test() { + val i = if (x != null) x.length else 0 + } +} \ No newline at end of file diff --git a/idea/testData/quickfix/smartCastImpossibleInIfThen/ifThenElse.kt.after b/idea/testData/quickfix/smartCastImpossibleInIfThen/ifThenElse.kt.after new file mode 100644 index 00000000000..80f60819557 --- /dev/null +++ b/idea/testData/quickfix/smartCastImpossibleInIfThen/ifThenElse.kt.after @@ -0,0 +1,8 @@ +// "Replace 'if' expression with elvis expression" "true" +class Test { + var x: String? = "" + + fun test() { + val i = x?.length ?: 0 + } +} \ No newline at end of file diff --git a/idea/testData/quickfix/smartCastImpossibleInIfThen/ifThenElse2.kt b/idea/testData/quickfix/smartCastImpossibleInIfThen/ifThenElse2.kt new file mode 100644 index 00000000000..91a5596acf9 --- /dev/null +++ b/idea/testData/quickfix/smartCastImpossibleInIfThen/ifThenElse2.kt @@ -0,0 +1,12 @@ +// "Replace 'if' expression with elvis expression" "true" +class Test { + var x: String? = "" + + fun test() { + val i = if (x != null) { + x.length + } else { + 0 + } + } +} \ No newline at end of file diff --git a/idea/testData/quickfix/smartCastImpossibleInIfThen/ifThenElse2.kt.after b/idea/testData/quickfix/smartCastImpossibleInIfThen/ifThenElse2.kt.after new file mode 100644 index 00000000000..80f60819557 --- /dev/null +++ b/idea/testData/quickfix/smartCastImpossibleInIfThen/ifThenElse2.kt.after @@ -0,0 +1,8 @@ +// "Replace 'if' expression with elvis expression" "true" +class Test { + var x: String? = "" + + fun test() { + val i = x?.length ?: 0 + } +} \ No newline at end of file diff --git a/idea/testData/quickfix/smartCastImpossibleInIfThen/ifThenElse3.kt b/idea/testData/quickfix/smartCastImpossibleInIfThen/ifThenElse3.kt new file mode 100644 index 00000000000..30b0f148f97 --- /dev/null +++ b/idea/testData/quickfix/smartCastImpossibleInIfThen/ifThenElse3.kt @@ -0,0 +1,13 @@ +// "Replace 'if' expression with elvis expression" "true" +// WITH_RUNTIME +class Test { + var x: String? = "" + + fun test() { + val i = if (x != null) foo(x) else bar() + } + + fun foo(s: String) = 1 + + fun bar() = 0 +} \ No newline at end of file diff --git a/idea/testData/quickfix/smartCastImpossibleInIfThen/ifThenElse3.kt.after b/idea/testData/quickfix/smartCastImpossibleInIfThen/ifThenElse3.kt.after new file mode 100644 index 00000000000..638b7a0404f --- /dev/null +++ b/idea/testData/quickfix/smartCastImpossibleInIfThen/ifThenElse3.kt.after @@ -0,0 +1,13 @@ +// "Replace 'if' expression with elvis expression" "true" +// WITH_RUNTIME +class Test { + var x: String? = "" + + fun test() { + val i = x?.let { foo(it) } ?: bar() + } + + fun foo(s: String) = 1 + + fun bar() = 0 +} \ No newline at end of file diff --git a/idea/testData/quickfix/smartCastImpossibleInIfThen/ifThenElse4.kt b/idea/testData/quickfix/smartCastImpossibleInIfThen/ifThenElse4.kt new file mode 100644 index 00000000000..bb355b730fe --- /dev/null +++ b/idea/testData/quickfix/smartCastImpossibleInIfThen/ifThenElse4.kt @@ -0,0 +1,8 @@ +// "Replace 'if' expression with elvis expression" "true" +class Test { + var x: Any? = null + + fun test() { + val i = if (x is String) x.length else 0 + } +} \ No newline at end of file diff --git a/idea/testData/quickfix/smartCastImpossibleInIfThen/ifThenElse4.kt.after b/idea/testData/quickfix/smartCastImpossibleInIfThen/ifThenElse4.kt.after new file mode 100644 index 00000000000..1df10c24503 --- /dev/null +++ b/idea/testData/quickfix/smartCastImpossibleInIfThen/ifThenElse4.kt.after @@ -0,0 +1,8 @@ +// "Replace 'if' expression with elvis expression" "true" +class Test { + var x: Any? = null + + fun test() { + val i = (x as? String)?.length ?: 0 + } +} \ No newline at end of file diff --git a/idea/testData/quickfix/smartCastImpossibleInIfThen/ifThenElse5.kt b/idea/testData/quickfix/smartCastImpossibleInIfThen/ifThenElse5.kt new file mode 100644 index 00000000000..0dd6a78a4a4 --- /dev/null +++ b/idea/testData/quickfix/smartCastImpossibleInIfThen/ifThenElse5.kt @@ -0,0 +1,13 @@ +// "Replace 'if' expression with elvis expression" "true" +// WITH_RUNTIME +class Test { + var x: Any? = null + + fun test() { + val i = if (x is String) foo(x) else bar() + } + + fun foo(s: String) = 1 + + fun bar() = 0 +} \ No newline at end of file diff --git a/idea/testData/quickfix/smartCastImpossibleInIfThen/ifThenElse5.kt.after b/idea/testData/quickfix/smartCastImpossibleInIfThen/ifThenElse5.kt.after new file mode 100644 index 00000000000..c09f749163c --- /dev/null +++ b/idea/testData/quickfix/smartCastImpossibleInIfThen/ifThenElse5.kt.after @@ -0,0 +1,13 @@ +// "Replace 'if' expression with elvis expression" "true" +// WITH_RUNTIME +class Test { + var x: Any? = null + + fun test() { + val i = (x as? String)?.let { foo(it) } ?: bar() + } + + fun foo(s: String) = 1 + + fun bar() = 0 +} \ No newline at end of file diff --git a/idea/testData/quickfix/smartCastImpossibleInIfThen/ifThenElseMultiStatement.kt b/idea/testData/quickfix/smartCastImpossibleInIfThen/ifThenElseMultiStatement.kt new file mode 100644 index 00000000000..09960db5098 --- /dev/null +++ b/idea/testData/quickfix/smartCastImpossibleInIfThen/ifThenElseMultiStatement.kt @@ -0,0 +1,18 @@ +// "Replace 'if' expression with elvis expression" "false" +// ACTION: Add non-null asserted (!!) call +// ACTION: Introduce local variable +// DISABLE-ERRORS +class Test { + var x: String? = "" + + fun test() { + val i = if (x != null) { + bar() + x.length + } else { + 0 + } + } + + fun bar() {} +} \ No newline at end of file diff --git a/idea/testData/quickfix/smartCastImpossibleInIfThen/ifThenMultiStatement.kt b/idea/testData/quickfix/smartCastImpossibleInIfThen/ifThenMultiStatement.kt new file mode 100644 index 00000000000..5d1ab56d3ce --- /dev/null +++ b/idea/testData/quickfix/smartCastImpossibleInIfThen/ifThenMultiStatement.kt @@ -0,0 +1,16 @@ +// "Replace 'if' expression with safe access expression" "false" +// ACTION: Add non-null asserted (!!) call +// ACTION: Introduce local variable +// DISABLE-ERRORS +class Test { + var x: String? = "" + + fun test() { + if (x != null) { + bar() + x.length + } + } + + fun bar() {} +} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixMultiFileTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixMultiFileTestGenerated.java index 7ff2c247133..a82ad65fead 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixMultiFileTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixMultiFileTestGenerated.java @@ -3751,6 +3751,19 @@ public class QuickFixMultiFileTestGenerated extends AbstractQuickFixMultiFileTes } } + @TestMetadata("idea/testData/quickfix/smartCastImpossibleInIfThen") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class SmartCastImpossibleInIfThen extends AbstractQuickFixMultiFileTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTestWithExtraFile, TargetBackend.ANY, testDataFilePath); + } + + public void testAllFilesPresentInSmartCastImpossibleInIfThen() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/quickfix/smartCastImpossibleInIfThen"), Pattern.compile("^(\\w+)\\.((before\\.Main\\.\\w+)|(test))$"), TargetBackend.ANY, true); + } + } + @TestMetadata("idea/testData/quickfix/specifyOverrideExplicitly") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java index e33ad7fb49a..f91ee3d70a1 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java @@ -10311,6 +10311,79 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest { } } + @TestMetadata("idea/testData/quickfix/smartCastImpossibleInIfThen") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class SmartCastImpossibleInIfThen extends AbstractQuickFixTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, TargetBackend.ANY, testDataFilePath); + } + + public void testAllFilesPresentInSmartCastImpossibleInIfThen() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/quickfix/smartCastImpossibleInIfThen"), Pattern.compile("^([\\w\\-_]+)\\.kt$"), TargetBackend.ANY, true); + } + + @TestMetadata("ifThen.kt") + public void testIfThen() throws Exception { + runTest("idea/testData/quickfix/smartCastImpossibleInIfThen/ifThen.kt"); + } + + @TestMetadata("ifThen2.kt") + public void testIfThen2() throws Exception { + runTest("idea/testData/quickfix/smartCastImpossibleInIfThen/ifThen2.kt"); + } + + @TestMetadata("ifThen3.kt") + public void testIfThen3() throws Exception { + runTest("idea/testData/quickfix/smartCastImpossibleInIfThen/ifThen3.kt"); + } + + @TestMetadata("ifThen4.kt") + public void testIfThen4() throws Exception { + runTest("idea/testData/quickfix/smartCastImpossibleInIfThen/ifThen4.kt"); + } + + @TestMetadata("ifThen5.kt") + public void testIfThen5() throws Exception { + runTest("idea/testData/quickfix/smartCastImpossibleInIfThen/ifThen5.kt"); + } + + @TestMetadata("ifThenElse.kt") + public void testIfThenElse() throws Exception { + runTest("idea/testData/quickfix/smartCastImpossibleInIfThen/ifThenElse.kt"); + } + + @TestMetadata("ifThenElse2.kt") + public void testIfThenElse2() throws Exception { + runTest("idea/testData/quickfix/smartCastImpossibleInIfThen/ifThenElse2.kt"); + } + + @TestMetadata("ifThenElse3.kt") + public void testIfThenElse3() throws Exception { + runTest("idea/testData/quickfix/smartCastImpossibleInIfThen/ifThenElse3.kt"); + } + + @TestMetadata("ifThenElse4.kt") + public void testIfThenElse4() throws Exception { + runTest("idea/testData/quickfix/smartCastImpossibleInIfThen/ifThenElse4.kt"); + } + + @TestMetadata("ifThenElse5.kt") + public void testIfThenElse5() throws Exception { + runTest("idea/testData/quickfix/smartCastImpossibleInIfThen/ifThenElse5.kt"); + } + + @TestMetadata("ifThenElseMultiStatement.kt") + public void testIfThenElseMultiStatement() throws Exception { + runTest("idea/testData/quickfix/smartCastImpossibleInIfThen/ifThenElseMultiStatement.kt"); + } + + @TestMetadata("ifThenMultiStatement.kt") + public void testIfThenMultiStatement() throws Exception { + runTest("idea/testData/quickfix/smartCastImpossibleInIfThen/ifThenMultiStatement.kt"); + } + } + @TestMetadata("idea/testData/quickfix/specifyOverrideExplicitly") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class)