diff --git a/idea/resources/META-INF/plugin-common.xml b/idea/resources/META-INF/plugin-common.xml index 3b4468abd09..dbf6b0c3414 100644 --- a/idea/resources/META-INF/plugin-common.xml +++ b/idea/resources/META-INF/plugin-common.xml @@ -3149,6 +3149,16 @@ language="kotlin" /> + + + +This inspection reports redundant labels. + + diff --git a/idea/src/org/jetbrains/kotlin/idea/inspections/migration/RedundantLabelMigrationInspection.kt b/idea/src/org/jetbrains/kotlin/idea/inspections/migration/RedundantLabelMigrationInspection.kt new file mode 100644 index 00000000000..66cc84deb3f --- /dev/null +++ b/idea/src/org/jetbrains/kotlin/idea/inspections/migration/RedundantLabelMigrationInspection.kt @@ -0,0 +1,27 @@ +/* + * 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.inspections.migration + +import com.intellij.codeInspection.CleanupLocalInspectionTool +import org.jetbrains.kotlin.config.LanguageVersion +import org.jetbrains.kotlin.diagnostics.Errors +import org.jetbrains.kotlin.idea.configuration.MigrationInfo +import org.jetbrains.kotlin.idea.configuration.isLanguageVersionUpdate +import org.jetbrains.kotlin.idea.quickfix.migration.MigrationFix +import org.jetbrains.kotlin.psi.KtElement + + +class RedundantLabelMigrationInspection : + AbstractDiagnosticBasedMigrationInspection(Errors.REDUNDANT_LABEL_WARNING, KtElement::class.java), + MigrationFix, + CleanupLocalInspectionTool { + override fun isApplicable(migrationInfo: MigrationInfo): Boolean { + return migrationInfo.isLanguageVersionUpdate(LanguageVersion.KOTLIN_1_3, LanguageVersion.KOTLIN_1_4) + } + + override fun descriptionMessage(): String = "Redundant label" +} + diff --git a/idea/testData/inspectionsLocal/redundantLabelMigration/.inspection b/idea/testData/inspectionsLocal/redundantLabelMigration/.inspection new file mode 100644 index 00000000000..af85879b39d --- /dev/null +++ b/idea/testData/inspectionsLocal/redundantLabelMigration/.inspection @@ -0,0 +1 @@ +org.jetbrains.kotlin.idea.inspections.migration.RedundantLabelMigrationInspection diff --git a/idea/testData/inspectionsLocal/redundantLabelMigration/simple.kt b/idea/testData/inspectionsLocal/redundantLabelMigration/simple.kt new file mode 100644 index 00000000000..264063e5e1a --- /dev/null +++ b/idea/testData/inspectionsLocal/redundantLabelMigration/simple.kt @@ -0,0 +1,8 @@ +// LANGUAGE_VERSION: 1.4 +// PROBLEM: none +// ERROR: Target label does not denote a function + +fun testValLabelInReturn() { + L@ val fn = { return@L } + fn() +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/redundantLabelMigration/simple2.kt b/idea/testData/inspectionsLocal/redundantLabelMigration/simple2.kt new file mode 100644 index 00000000000..3b8df7fad2c --- /dev/null +++ b/idea/testData/inspectionsLocal/redundantLabelMigration/simple2.kt @@ -0,0 +1,7 @@ +// LANGUAGE_VERSION: 1.4 +// DISABLE-ERRORS + +fun testValLabelInReturn() { + L@ val fn = { return@L } + fn() +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/redundantLabelMigration/simple2.kt.after b/idea/testData/inspectionsLocal/redundantLabelMigration/simple2.kt.after new file mode 100644 index 00000000000..2daef3341bc --- /dev/null +++ b/idea/testData/inspectionsLocal/redundantLabelMigration/simple2.kt.after @@ -0,0 +1,7 @@ +// LANGUAGE_VERSION: 1.4 +// DISABLE-ERRORS + +fun testValLabelInReturn() { + val fn = { return@L } + fn() +} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java index 87f9bbfac85..5585db3f7e1 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java @@ -7240,6 +7240,29 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest { } } + @TestMetadata("idea/testData/inspectionsLocal/redundantLabelMigration") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class RedundantLabelMigration extends AbstractLocalInspectionTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); + } + + public void testAllFilesPresentInRedundantLabelMigration() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("idea/testData/inspectionsLocal/redundantLabelMigration"), Pattern.compile("^([\\w\\-_]+)\\.(kt|kts)$"), null, true); + } + + @TestMetadata("simple.kt") + public void testSimple() throws Exception { + runTest("idea/testData/inspectionsLocal/redundantLabelMigration/simple.kt"); + } + + @TestMetadata("simple2.kt") + public void testSimple2() throws Exception { + runTest("idea/testData/inspectionsLocal/redundantLabelMigration/simple2.kt"); + } + } + @TestMetadata("idea/testData/inspectionsLocal/redundantLambdaArrow") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class)