Create RedundantLabelMigrationInspection

#KT-36262
This commit is contained in:
Dmitry Gridin
2020-01-29 13:35:05 +07:00
parent 2441ee80e4
commit 311860699e
8 changed files with 88 additions and 0 deletions
+10
View File
@@ -3149,6 +3149,16 @@
language="kotlin"
/>
<localInspection implementationClass="org.jetbrains.kotlin.idea.inspections.migration.RedundantLabelMigrationInspection"
displayName="Redundant labels since 1.4"
groupPath="Kotlin"
groupName="Migration"
enabledByDefault="false"
cleanupTool="true"
level="WEAK WARNING"
language="kotlin"
/>
<localInspection implementationClass="org.jetbrains.kotlin.idea.inspections.migration.ObsoleteExperimentalCoroutinesInspection"
displayName="Experimental coroutines usages are deprecated since 1.3"
groupPath="Kotlin"
@@ -0,0 +1,5 @@
<html>
<body>
This inspection reports redundant labels.
</body>
</html>
@@ -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<KtElement>(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"
}
@@ -0,0 +1 @@
org.jetbrains.kotlin.idea.inspections.migration.RedundantLabelMigrationInspection
@@ -0,0 +1,8 @@
// LANGUAGE_VERSION: 1.4
// PROBLEM: none
// ERROR: Target label does not denote a function
fun testValLabelInReturn() {
L@ val fn = { <caret>return@L }
fn()
}
@@ -0,0 +1,7 @@
// LANGUAGE_VERSION: 1.4
// DISABLE-ERRORS
fun testValLabelInReturn() {
<caret>L@ val fn = { return@L }
fn()
}
@@ -0,0 +1,7 @@
// LANGUAGE_VERSION: 1.4
// DISABLE-ERRORS
fun testValLabelInReturn() {
val fn = { return@L }
fn()
}
@@ -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)