diff --git a/plugins/kotlin/code-insight/fixes-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/fixes/CreateLabelFixFactory.kt b/plugins/kotlin/code-insight/fixes-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/fixes/CreateLabelFixFactory.kt index 4045ee167b8f..c84bce6be51e 100644 --- a/plugins/kotlin/code-insight/fixes-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/fixes/CreateLabelFixFactory.kt +++ b/plugins/kotlin/code-insight/fixes-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/fixes/CreateLabelFixFactory.kt @@ -15,15 +15,19 @@ internal object CreateLabelFixFactory { val labelReferenceExpression = diagnostic.psi as? KtLabelReferenceExpression ?: return@IntentionBased emptyList() val fixes = when ((labelReferenceExpression.parent as? KtContainerNode)?.parent) { is KtBreakExpression, is KtContinueExpression -> { - if (labelReferenceExpression.getContainingLoops() - .any() - ) listOf(CreateLabelFix.ForLoop(labelReferenceExpression)) else emptyList() + if (labelReferenceExpression.getContainingLoops().any()) { + listOf(CreateLabelFix.ForLoop(labelReferenceExpression)) + } else { + emptyList() + } } is KtReturnExpression -> { - if (labelReferenceExpression.getContainingLambdas() - .any() - ) listOf(CreateLabelFix.ForLambda(labelReferenceExpression)) else emptyList() + if (labelReferenceExpression.getContainingLambdas().any()) { + listOf(CreateLabelFix.ForLambda(labelReferenceExpression)) + } else { + emptyList() + } } else -> emptyList() diff --git a/plugins/kotlin/code-insight/fixes-k2/tests/test/org/jetbrains/kotlin/idea/k2/codeinsight/fixes/HighLevelQuickFixTestGenerated.java b/plugins/kotlin/code-insight/fixes-k2/tests/test/org/jetbrains/kotlin/idea/k2/codeinsight/fixes/HighLevelQuickFixTestGenerated.java index 05e97c94c5b0..fc6787342352 100644 --- a/plugins/kotlin/code-insight/fixes-k2/tests/test/org/jetbrains/kotlin/idea/k2/codeinsight/fixes/HighLevelQuickFixTestGenerated.java +++ b/plugins/kotlin/code-insight/fixes-k2/tests/test/org/jetbrains/kotlin/idea/k2/codeinsight/fixes/HighLevelQuickFixTestGenerated.java @@ -7122,7 +7122,64 @@ public abstract class HighLevelQuickFixTestGenerated extends AbstractHighLevelQu + @RunWith(JUnit3RunnerWithInners.class) + @TestMetadata("../../../idea/tests/testData/quickfix/createLabel") + public static class CreateLabel extends AbstractHighLevelQuickFixTest { + @java.lang.Override + @org.jetbrains.annotations.NotNull + public final KotlinPluginMode getPluginMode() { + return KotlinPluginMode.K2; + } + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); + } + + @TestMetadata("breakInLoop.kt") + public void testBreakInLoop() throws Exception { + runTest("../../../idea/tests/testData/quickfix/createLabel/breakInLoop.kt"); + } + + @TestMetadata("breakInOuterLoop.kt") + public void testBreakInOuterLoop() throws Exception { + runTest("../../../idea/tests/testData/quickfix/createLabel/breakInOuterLoop.kt"); + } + + @TestMetadata("breakInlambdaBeforeLoop.kt") + public void testBreakInlambdaBeforeLoop() throws Exception { + runTest("../../../idea/tests/testData/quickfix/createLabel/breakInlambdaBeforeLoop.kt"); + } + + @TestMetadata("breakNoLoop.kt") + public void testBreakNoLoop() throws Exception { + runTest("../../../idea/tests/testData/quickfix/createLabel/breakNoLoop.kt"); + } + + @TestMetadata("continueInLoop.kt") + public void testContinueInLoop() throws Exception { + runTest("../../../idea/tests/testData/quickfix/createLabel/continueInLoop.kt"); + } + + @TestMetadata("continueNoLoop.kt") + public void testContinueNoLoop() throws Exception { + runTest("../../../idea/tests/testData/quickfix/createLabel/continueNoLoop.kt"); + } + + @TestMetadata("returnInLambda.kt") + public void testReturnInLambda() throws Exception { + runTest("../../../idea/tests/testData/quickfix/createLabel/returnInLambda.kt"); + } + + @TestMetadata("returnInOuterLambda.kt") + public void testReturnInOuterLambda() throws Exception { + runTest("../../../idea/tests/testData/quickfix/createLabel/returnInOuterLambda.kt"); + } + + @TestMetadata("returnNoLambda.kt") + public void testReturnNoLambda() throws Exception { + runTest("../../../idea/tests/testData/quickfix/createLabel/returnNoLambda.kt"); + } + } diff --git a/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/quickfix/CreateLabelFixFactory.kt b/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/quickfix/CreateLabelFixFactory.kt index 41a2be15ded9..950e6c3911e9 100644 --- a/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/quickfix/CreateLabelFixFactory.kt +++ b/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/quickfix/CreateLabelFixFactory.kt @@ -14,11 +14,19 @@ internal object CreateLabelFixFactory : KotlinSingleIntentionActionFactory() { val labelReferenceExpression = diagnostic.psiElement as? KtLabelReferenceExpression ?: return null return when ((labelReferenceExpression.parent as? KtContainerNode)?.parent) { is KtBreakExpression, is KtContinueExpression -> { - if (labelReferenceExpression.getContainingLoops().any()) CreateLabelFix.ForLoop(labelReferenceExpression) else null + if (labelReferenceExpression.getContainingLoops().any()) { + CreateLabelFix.ForLoop(labelReferenceExpression) + } else { + null + } } is KtReturnExpression -> { - if (labelReferenceExpression.getContainingLambdas().any()) CreateLabelFix.ForLambda(labelReferenceExpression) else null + if (labelReferenceExpression.getContainingLambdas().any()) { + CreateLabelFix.ForLambda(labelReferenceExpression) + } else { + null + } } else -> null diff --git a/plugins/kotlin/idea/tests/testData/quickfix/createLabel/breakInLoop.kt b/plugins/kotlin/idea/tests/testData/quickfix/createLabel/breakInLoop.kt index 66a75fea693e..efe3f864ca51 100644 --- a/plugins/kotlin/idea/tests/testData/quickfix/createLabel/breakInLoop.kt +++ b/plugins/kotlin/idea/tests/testData/quickfix/createLabel/breakInLoop.kt @@ -1,4 +1,6 @@ -// IGNORE_K2 +/* IGNORE_K2 */ +// Remove this ignoring after KT-69829 is fixed + // "Create label foo@" "true" fun test() { diff --git a/plugins/kotlin/idea/tests/testData/quickfix/createLabel/breakInLoop.kt.after b/plugins/kotlin/idea/tests/testData/quickfix/createLabel/breakInLoop.kt.after index d6732ddcc65a..884b21fec49d 100644 --- a/plugins/kotlin/idea/tests/testData/quickfix/createLabel/breakInLoop.kt.after +++ b/plugins/kotlin/idea/tests/testData/quickfix/createLabel/breakInLoop.kt.after @@ -1,4 +1,6 @@ -// IGNORE_K2 +/* IGNORE_K2 */ +// Remove this ignoring after KT-69829 is fixed + // "Create label foo@" "true" fun test() { diff --git a/plugins/kotlin/idea/tests/testData/quickfix/createLabel/breakInOuterLoop.kt b/plugins/kotlin/idea/tests/testData/quickfix/createLabel/breakInOuterLoop.kt index a1fd041bf940..0404c6bda2e7 100644 --- a/plugins/kotlin/idea/tests/testData/quickfix/createLabel/breakInOuterLoop.kt +++ b/plugins/kotlin/idea/tests/testData/quickfix/createLabel/breakInOuterLoop.kt @@ -1,4 +1,6 @@ -// IGNORE_K2 +/* IGNORE_K2 */ +// Remove this ignoring after KT-69829 is fixed + // "Create label foo@" "true" fun test() { diff --git a/plugins/kotlin/idea/tests/testData/quickfix/createLabel/breakInOuterLoop.kt.after b/plugins/kotlin/idea/tests/testData/quickfix/createLabel/breakInOuterLoop.kt.after index e55de51107db..ebe1143ec924 100644 --- a/plugins/kotlin/idea/tests/testData/quickfix/createLabel/breakInOuterLoop.kt.after +++ b/plugins/kotlin/idea/tests/testData/quickfix/createLabel/breakInOuterLoop.kt.after @@ -1,4 +1,6 @@ -// IGNORE_K2 +/* IGNORE_K2 */ +// Remove this ignoring after KT-69829 is fixed + // "Create label foo@" "true" fun test() { diff --git a/plugins/kotlin/idea/tests/testData/quickfix/createLabel/breakInlambdaBeforeLoop.kt b/plugins/kotlin/idea/tests/testData/quickfix/createLabel/breakInlambdaBeforeLoop.kt index 7eb706f72eb5..f9a23b860a40 100644 --- a/plugins/kotlin/idea/tests/testData/quickfix/createLabel/breakInlambdaBeforeLoop.kt +++ b/plugins/kotlin/idea/tests/testData/quickfix/createLabel/breakInlambdaBeforeLoop.kt @@ -1,4 +1,3 @@ -// IGNORE_K2 // "Create label foo@" "false" // ERROR: The label '@foo' does not denote a loop // ERROR: Unresolved reference: @foo diff --git a/plugins/kotlin/idea/tests/testData/quickfix/createLabel/continueInLoop.kt b/plugins/kotlin/idea/tests/testData/quickfix/createLabel/continueInLoop.kt index 86836952ecf1..3abc1560d778 100644 --- a/plugins/kotlin/idea/tests/testData/quickfix/createLabel/continueInLoop.kt +++ b/plugins/kotlin/idea/tests/testData/quickfix/createLabel/continueInLoop.kt @@ -1,3 +1,6 @@ +/* IGNORE_K2 */ +// Remove this ignoring after KT-69829 is fixed + // "Create label foo@" "true" fun test() { diff --git a/plugins/kotlin/idea/tests/testData/quickfix/createLabel/continueInLoop.kt.after b/plugins/kotlin/idea/tests/testData/quickfix/createLabel/continueInLoop.kt.after index c8da74914761..f7df6a208bf7 100644 --- a/plugins/kotlin/idea/tests/testData/quickfix/createLabel/continueInLoop.kt.after +++ b/plugins/kotlin/idea/tests/testData/quickfix/createLabel/continueInLoop.kt.after @@ -1,3 +1,6 @@ +/* IGNORE_K2 */ +// Remove this ignoring after KT-69829 is fixed + // "Create label foo@" "true" fun test() { diff --git a/plugins/kotlin/idea/tests/testData/quickfix/createLabel/returnInLambda.kt b/plugins/kotlin/idea/tests/testData/quickfix/createLabel/returnInLambda.kt index 0e0f042a0dd6..c1e06dfc2951 100644 --- a/plugins/kotlin/idea/tests/testData/quickfix/createLabel/returnInLambda.kt +++ b/plugins/kotlin/idea/tests/testData/quickfix/createLabel/returnInLambda.kt @@ -1,3 +1,6 @@ +/* IGNORE_K2 */ +// Remove this ignoring after KT-69829 is fixed + // "Create label foo@" "true" inline fun Int.bar(f: (Int) -> Unit) { } diff --git a/plugins/kotlin/idea/tests/testData/quickfix/createLabel/returnInLambda.kt.after b/plugins/kotlin/idea/tests/testData/quickfix/createLabel/returnInLambda.kt.after index afc60e8f92f9..88032abe9f6b 100644 --- a/plugins/kotlin/idea/tests/testData/quickfix/createLabel/returnInLambda.kt.after +++ b/plugins/kotlin/idea/tests/testData/quickfix/createLabel/returnInLambda.kt.after @@ -1,3 +1,6 @@ +/* IGNORE_K2 */ +// Remove this ignoring after KT-69829 is fixed + // "Create label foo@" "true" inline fun Int.bar(f: (Int) -> Unit) { } diff --git a/plugins/kotlin/idea/tests/testData/quickfix/createLabel/returnInOuterLambda.kt b/plugins/kotlin/idea/tests/testData/quickfix/createLabel/returnInOuterLambda.kt index 1010df00360a..47f67ade81b2 100644 --- a/plugins/kotlin/idea/tests/testData/quickfix/createLabel/returnInOuterLambda.kt +++ b/plugins/kotlin/idea/tests/testData/quickfix/createLabel/returnInOuterLambda.kt @@ -1,3 +1,6 @@ +/* IGNORE_K2 */ +// Remove this ignoring after KT-69829 is fixed + // "Create label foo@" "true" inline fun Int.bar(f: (Int) -> Unit) { } diff --git a/plugins/kotlin/idea/tests/testData/quickfix/createLabel/returnInOuterLambda.kt.after b/plugins/kotlin/idea/tests/testData/quickfix/createLabel/returnInOuterLambda.kt.after index d4efe8f9a754..0f4663741ec8 100644 --- a/plugins/kotlin/idea/tests/testData/quickfix/createLabel/returnInOuterLambda.kt.after +++ b/plugins/kotlin/idea/tests/testData/quickfix/createLabel/returnInOuterLambda.kt.after @@ -1,3 +1,6 @@ +/* IGNORE_K2 */ +// Remove this ignoring after KT-69829 is fixed + // "Create label foo@" "true" inline fun Int.bar(f: (Int) -> Unit) { } diff --git a/plugins/kotlin/util/test-generator-fir/test/org/jetbrains/kotlin/fir/testGenerator/codeinsight/GenerateK2QuickFixTests.kt b/plugins/kotlin/util/test-generator-fir/test/org/jetbrains/kotlin/fir/testGenerator/codeinsight/GenerateK2QuickFixTests.kt index 912f37ba9666..07a1e8b9def4 100644 --- a/plugins/kotlin/util/test-generator-fir/test/org/jetbrains/kotlin/fir/testGenerator/codeinsight/GenerateK2QuickFixTests.kt +++ b/plugins/kotlin/util/test-generator-fir/test/org/jetbrains/kotlin/fir/testGenerator/codeinsight/GenerateK2QuickFixTests.kt @@ -110,7 +110,7 @@ internal fun MutableTWorkspace.generateK2FixTests() { model("$idea/quickfix/convertToAnonymousObject", pattern = pattern, isIgnored = true) model("$idea/quickfix/convertToIsArrayOfCall", pattern = pattern) model("$idea/quickfix/createFromUsage", pattern = pattern, isIgnored = true) - model("$idea/quickfix/createLabel", pattern = pattern, isIgnored = true) // Remove `isIgnored` after KT-69829 is fixed + model("$idea/quickfix/createLabel", pattern = pattern) model("$idea/quickfix/declarationCantBeInlined", pattern = pattern, isIgnored = true) model("$idea/quickfix/declaringJavaClass", pattern = pattern, isIgnored = true) model("$idea/quickfix/decreaseVisibility", pattern = pattern)