From 0ae21a157f24c707fe580da24aff1f0d89e7e0f9 Mon Sep 17 00:00:00 2001 From: Yan Zhulanow Date: Sat, 24 Oct 2020 00:20:41 +0900 Subject: [PATCH] Revert ""Change to return with label" quick fix: apply for type mismatch" This reverts commit f76e9886 --- .../idea/quickfix/ChangeToLabeledReturnFix.kt | 25 +++---------------- .../kotlin/idea/quickfix/QuickFixRegistrar.kt | 3 --- .../constantExpectedTypeMismatch.kt | 9 ------- .../constantExpectedTypeMismatch.kt.after | 9 ------- .../nullForNonnullType.kt | 11 -------- .../nullForNonnullType.kt.after | 11 -------- .../nullForNonnullType2.kt | 14 ----------- .../changeToLabeledReturn/typeMismatch.kt | 11 -------- .../typeMismatch.kt.after | 11 -------- .../changeToLabeledReturn/typeMismatch2.kt | 19 -------------- .../idea/quickfix/QuickFixTestGenerated.java | 25 ------------------- 11 files changed, 3 insertions(+), 145 deletions(-) delete mode 100644 idea/testData/quickfix/changeToLabeledReturn/constantExpectedTypeMismatch.kt delete mode 100644 idea/testData/quickfix/changeToLabeledReturn/constantExpectedTypeMismatch.kt.after delete mode 100644 idea/testData/quickfix/changeToLabeledReturn/nullForNonnullType.kt delete mode 100644 idea/testData/quickfix/changeToLabeledReturn/nullForNonnullType.kt.after delete mode 100644 idea/testData/quickfix/changeToLabeledReturn/nullForNonnullType2.kt delete mode 100644 idea/testData/quickfix/changeToLabeledReturn/typeMismatch.kt delete mode 100644 idea/testData/quickfix/changeToLabeledReturn/typeMismatch.kt.after delete mode 100644 idea/testData/quickfix/changeToLabeledReturn/typeMismatch2.kt diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/ChangeToLabeledReturnFix.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/ChangeToLabeledReturnFix.kt index 93ca545289f..8baa3f6007e 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/ChangeToLabeledReturnFix.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/ChangeToLabeledReturnFix.kt @@ -9,19 +9,15 @@ import com.intellij.codeInsight.intention.IntentionAction import com.intellij.openapi.editor.Editor import com.intellij.openapi.project.Project import org.jetbrains.kotlin.diagnostics.Diagnostic -import org.jetbrains.kotlin.diagnostics.Errors import org.jetbrains.kotlin.idea.KotlinBundle import org.jetbrains.kotlin.idea.caches.resolve.analyze import org.jetbrains.kotlin.idea.util.findLabelAndCall import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.psi.* -import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType import org.jetbrains.kotlin.psi.psiUtil.parentsWithSelf import org.jetbrains.kotlin.renderer.render import org.jetbrains.kotlin.resolve.BindingContext -import org.jetbrains.kotlin.resolve.calls.callUtil.getType import org.jetbrains.kotlin.resolve.inline.InlineUtil -import org.jetbrains.kotlin.types.typeUtil.isSubtypeOf class ChangeToLabeledReturnFix( element: KtReturnExpression, val labeledReturn: String @@ -60,24 +56,9 @@ class ChangeToLabeledReturnFix( } override fun doCreateActions(diagnostic: Diagnostic): List { - val element = diagnostic.psiElement as? KtElement ?: return emptyList() - val context by lazy { element.analyze() } - val returnExpression = when (diagnostic.factory) { - Errors.RETURN_NOT_ALLOWED -> { - diagnostic.psiElement as? KtReturnExpression - } - Errors.TYPE_MISMATCH, Errors.CONSTANT_EXPECTED_TYPE_MISMATCH, Errors.NULL_FOR_NONNULL_TYPE -> { - val returnExpression = diagnostic.psiElement.getStrictParentOfType() ?: return emptyList() - val lambda = returnExpression.getStrictParentOfType() ?: return emptyList() - val lambdaReturnType = context[BindingContext.FUNCTION, lambda.functionLiteral]?.returnType ?: return emptyList() - val returnType = returnExpression.returnedExpression?.getType(context) ?: return emptyList() - if (!returnType.isSubtypeOf(lambdaReturnType)) return emptyList() - returnExpression - } - else -> null - } ?: return emptyList() - return findAccessibleLabels(context, returnExpression).map { - ChangeToLabeledReturnFix(returnExpression, labeledReturn = "return@${it.render()}") + val expression = diagnostic.psiElement as? KtReturnExpression ?: return emptyList() + return findAccessibleLabels(expression.analyze(), expression).map { + ChangeToLabeledReturnFix(expression, labeledReturn = "return@${it.render()}") } } } diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/QuickFixRegistrar.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/QuickFixRegistrar.kt index 407da4888ea..4a5a367c68f 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/QuickFixRegistrar.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/QuickFixRegistrar.kt @@ -570,9 +570,6 @@ class QuickFixRegistrar : QuickFixContributor { MUST_BE_INITIALIZED_OR_BE_ABSTRACT.registerFactory(AddModifierFix.AddLateinitFactory) RETURN_NOT_ALLOWED.registerFactory(ChangeToLabeledReturnFix) - TYPE_MISMATCH.registerFactory(ChangeToLabeledReturnFix) - CONSTANT_EXPECTED_TYPE_MISMATCH.registerFactory(ChangeToLabeledReturnFix) - NULL_FOR_NONNULL_TYPE.registerFactory(ChangeToLabeledReturnFix) WRONG_ANNOTATION_TARGET.registerFactory(AddAnnotationTargetFix) WRONG_ANNOTATION_TARGET_WITH_USE_SITE_TARGET.registerFactory(MoveReceiverAnnotationFix, AddAnnotationTargetFix) diff --git a/idea/testData/quickfix/changeToLabeledReturn/constantExpectedTypeMismatch.kt b/idea/testData/quickfix/changeToLabeledReturn/constantExpectedTypeMismatch.kt deleted file mode 100644 index 11583616ee4..00000000000 --- a/idea/testData/quickfix/changeToLabeledReturn/constantExpectedTypeMismatch.kt +++ /dev/null @@ -1,9 +0,0 @@ -// "Change to 'return@foo'" "true" -inline fun foo(f: (Int) -> Int) {} - -fun test() { - foo { i -> - if (i == 1) return 1 - 0 - } -} \ No newline at end of file diff --git a/idea/testData/quickfix/changeToLabeledReturn/constantExpectedTypeMismatch.kt.after b/idea/testData/quickfix/changeToLabeledReturn/constantExpectedTypeMismatch.kt.after deleted file mode 100644 index ff400c20346..00000000000 --- a/idea/testData/quickfix/changeToLabeledReturn/constantExpectedTypeMismatch.kt.after +++ /dev/null @@ -1,9 +0,0 @@ -// "Change to 'return@foo'" "true" -inline fun foo(f: (Int) -> Int) {} - -fun test() { - foo { i -> - if (i == 1) return@foo 1 - 0 - } -} \ No newline at end of file diff --git a/idea/testData/quickfix/changeToLabeledReturn/nullForNonnullType.kt b/idea/testData/quickfix/changeToLabeledReturn/nullForNonnullType.kt deleted file mode 100644 index 4be6a69aebf..00000000000 --- a/idea/testData/quickfix/changeToLabeledReturn/nullForNonnullType.kt +++ /dev/null @@ -1,11 +0,0 @@ -// "Change to 'return@foo'" "true" -inline fun foo(f: (Int) -> Int?) {} - -fun baz(): Int = 0 - -fun test() { - foo { i -> - if (i == 1) return null - 0 - } -} \ No newline at end of file diff --git a/idea/testData/quickfix/changeToLabeledReturn/nullForNonnullType.kt.after b/idea/testData/quickfix/changeToLabeledReturn/nullForNonnullType.kt.after deleted file mode 100644 index 9ed80eed18f..00000000000 --- a/idea/testData/quickfix/changeToLabeledReturn/nullForNonnullType.kt.after +++ /dev/null @@ -1,11 +0,0 @@ -// "Change to 'return@foo'" "true" -inline fun foo(f: (Int) -> Int?) {} - -fun baz(): Int = 0 - -fun test() { - foo { i -> - if (i == 1) return@foo null - 0 - } -} \ No newline at end of file diff --git a/idea/testData/quickfix/changeToLabeledReturn/nullForNonnullType2.kt b/idea/testData/quickfix/changeToLabeledReturn/nullForNonnullType2.kt deleted file mode 100644 index eee497c3257..00000000000 --- a/idea/testData/quickfix/changeToLabeledReturn/nullForNonnullType2.kt +++ /dev/null @@ -1,14 +0,0 @@ -// "Change to 'return@foo'" "false" -// ACTION: Add braces to 'if' statement -// ACTION: Change return type of enclosing function 'test' to 'Unit?' -// DISABLE-ERRORS -inline fun foo(f: (Int) -> Int) {} - -fun baz(): Int = 0 - -fun test() { - foo { i -> - if (i == 1) return null - 0 - } -} \ No newline at end of file diff --git a/idea/testData/quickfix/changeToLabeledReturn/typeMismatch.kt b/idea/testData/quickfix/changeToLabeledReturn/typeMismatch.kt deleted file mode 100644 index fbbafebbdd8..00000000000 --- a/idea/testData/quickfix/changeToLabeledReturn/typeMismatch.kt +++ /dev/null @@ -1,11 +0,0 @@ -// "Change to 'return@foo'" "true" -inline fun foo(f: (Int) -> Int) {} - -fun baz(): Int = 0 - -fun test() { - foo { i -> - if (i == 1) return baz() - 0 - } -} \ No newline at end of file diff --git a/idea/testData/quickfix/changeToLabeledReturn/typeMismatch.kt.after b/idea/testData/quickfix/changeToLabeledReturn/typeMismatch.kt.after deleted file mode 100644 index 3609a802f40..00000000000 --- a/idea/testData/quickfix/changeToLabeledReturn/typeMismatch.kt.after +++ /dev/null @@ -1,11 +0,0 @@ -// "Change to 'return@foo'" "true" -inline fun foo(f: (Int) -> Int) {} - -fun baz(): Int = 0 - -fun test() { - foo { i -> - if (i == 1) return@foo baz() - 0 - } -} \ No newline at end of file diff --git a/idea/testData/quickfix/changeToLabeledReturn/typeMismatch2.kt b/idea/testData/quickfix/changeToLabeledReturn/typeMismatch2.kt deleted file mode 100644 index 091eb4c83d7..00000000000 --- a/idea/testData/quickfix/changeToLabeledReturn/typeMismatch2.kt +++ /dev/null @@ -1,19 +0,0 @@ -// "Change to 'return@foo'" "false" -// ACTION: Add braces to 'if' statement -// ACTION: Change parameter 'f' type of function 'foo' to '(Int) -> Unit' -// ACTION: Change return type of called function 'baz' to 'Unit' -// ACTION: Change return type of enclosing function 'test' to 'String' -// ACTION: Convert to single-line lambda -// ACTION: Enable a trailing comma by default in the formatter -// ACTION: Move lambda argument into parentheses -// ACTION: Specify explicit lambda signature -// DISABLE-ERRORS -inline fun foo(f: (Int) -> Int) {} - -fun baz(): String = "" - -fun test() { - foo { i -> - if (i == 1) return baz() - } -} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java index 10b02e61085..622ef461ac0 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java @@ -2687,11 +2687,6 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest { KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("idea/testData/quickfix/changeToLabeledReturn"), Pattern.compile("^([\\w\\-_]+)\\.kt$"), null, true); } - @TestMetadata("constantExpectedTypeMismatch.kt") - public void testConstantExpectedTypeMismatch() throws Exception { - runTest("idea/testData/quickfix/changeToLabeledReturn/constantExpectedTypeMismatch.kt"); - } - @TestMetadata("multipleInner.kt") public void testMultipleInner() throws Exception { runTest("idea/testData/quickfix/changeToLabeledReturn/multipleInner.kt"); @@ -2711,26 +2706,6 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest { public void testNormal() throws Exception { runTest("idea/testData/quickfix/changeToLabeledReturn/normal.kt"); } - - @TestMetadata("nullForNonnullType.kt") - public void testNullForNonnullType() throws Exception { - runTest("idea/testData/quickfix/changeToLabeledReturn/nullForNonnullType.kt"); - } - - @TestMetadata("nullForNonnullType2.kt") - public void testNullForNonnullType2() throws Exception { - runTest("idea/testData/quickfix/changeToLabeledReturn/nullForNonnullType2.kt"); - } - - @TestMetadata("typeMismatch.kt") - public void testTypeMismatch() throws Exception { - runTest("idea/testData/quickfix/changeToLabeledReturn/typeMismatch.kt"); - } - - @TestMetadata("typeMismatch2.kt") - public void testTypeMismatch2() throws Exception { - runTest("idea/testData/quickfix/changeToLabeledReturn/typeMismatch2.kt"); - } } @TestMetadata("idea/testData/quickfix/changeToMutableCollection")