RestrictReturnStatementTargetMigrationInspection: add quickfix

#KT-36262 Fixed
This commit is contained in:
Dmitry Gridin
2020-01-29 15:07:27 +07:00
parent f1bad0c9ae
commit 181dd432ca
7 changed files with 50 additions and 1 deletions
@@ -627,6 +627,8 @@ class QuickFixRegistrar : QuickFixContributor {
CONSTRUCTOR_IN_OBJECT.registerFactory(ChangeObjectToClassFix)
REDUNDANT_LABEL_WARNING.registerFactory(RemoveRedundantLabelFix)
NOT_A_FUNCTION_LABEL.registerFactory(RemoveReturnLabelFix)
NOT_A_FUNCTION_LABEL_WARNING.registerFactory(RemoveReturnLabelFix)
ACCIDENTAL_OVERRIDE.registerFactory(MakePrivateAndOverrideMemberFix.AccidentalOverrideFactory)
@@ -23,7 +23,8 @@ class RemoveReturnLabelFix(element: KtReturnExpression) : KotlinQuickFixAction<K
companion object : KotlinSingleIntentionActionFactory() {
override fun createAction(diagnostic: Diagnostic): KotlinQuickFixAction<KtReturnExpression>? {
val returnExpression = diagnostic.psiElement as? KtReturnExpression ?: return null
return RemoveReturnLabelFix(returnExpression)
return if (returnExpression.labeledExpression == null) null
else RemoveReturnLabelFix(returnExpression)
}
}
}
@@ -0,0 +1 @@
org.jetbrains.kotlin.idea.inspections.migration.RestrictReturnStatementTargetMigrationInspection
@@ -0,0 +1,8 @@
// LANGUAGE_VERSION: 1.4
// PROBLEM: none
// ERROR: Target label does not denote a function
fun testValLabelInReturn() {
<caret>L@ val fn = { return@L }
fn()
}
@@ -0,0 +1,7 @@
// LANGUAGE_VERSION: 1.4
// SKIP_ERRORS_AFTER
fun testValLabelInReturn() {
L@ val fn = { return@L<caret> }
fn()
}
@@ -0,0 +1,7 @@
// LANGUAGE_VERSION: 1.4
// SKIP_ERRORS_AFTER
fun testValLabelInReturn() {
L@ val fn = { return }
fn()
}
@@ -10950,6 +10950,29 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest {
}
}
@TestMetadata("idea/testData/inspectionsLocal/restrictReturnStatementTargetMigration")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class RestrictReturnStatementTargetMigration extends AbstractLocalInspectionTest {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
}
public void testAllFilesPresentInRestrictReturnStatementTargetMigration() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("idea/testData/inspectionsLocal/restrictReturnStatementTargetMigration"), Pattern.compile("^([\\w\\-_]+)\\.(kt|kts)$"), null, true);
}
@TestMetadata("simple.kt")
public void testSimple() throws Exception {
runTest("idea/testData/inspectionsLocal/restrictReturnStatementTargetMigration/simple.kt");
}
@TestMetadata("simple2.kt")
public void testSimple2() throws Exception {
runTest("idea/testData/inspectionsLocal/restrictReturnStatementTargetMigration/simple2.kt");
}
}
@TestMetadata("idea/testData/inspectionsLocal/safeCastWithReturn")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)