Create ProhibitRepeatedUseSiteTargetAnnotationsMigrationInspection

#KT-36257 Fixed
This commit is contained in:
Dmitry Gridin
2020-01-29 17:55:01 +07:00
parent 266a7a67f0
commit 8d48d899d0
16 changed files with 296 additions and 0 deletions
+10
View File
@@ -3169,6 +3169,16 @@
language="kotlin"
/>
<localInspection implementationClass="org.jetbrains.kotlin.idea.inspections.migration.ProhibitRepeatedUseSiteTargetAnnotationsMigrationInspection"
displayName="This annotation is not repeatable since 1.4"
groupPath="Kotlin"
groupName="Migration"
enabledByDefault="false"
cleanupTool="true"
level="ERROR"
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>
Since Kotlin 1.4, it's forbidden to repeat annotation on property accessors.
</body>
</html>
@@ -0,0 +1,25 @@
/*
* 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.KtAnnotationEntry
class ProhibitRepeatedUseSiteTargetAnnotationsMigrationInspection :
AbstractDiagnosticBasedMigrationInspection<KtAnnotationEntry>(Errors.REPEATED_ANNOTATION, KtAnnotationEntry::class.java),
MigrationFix,
CleanupLocalInspectionTool {
override fun isApplicable(migrationInfo: MigrationInfo): Boolean {
return migrationInfo.isLanguageVersionUpdate(LanguageVersion.KOTLIN_1_3, LanguageVersion.KOTLIN_1_4)
}
}
@@ -633,6 +633,9 @@ class QuickFixRegistrar : QuickFixContributor {
ANNOTATION_ON_SUPERCLASS.registerFactory(RemoveAnnotationFix)
ANNOTATION_ON_SUPERCLASS_WARNING.registerFactory(RemoveAnnotationFix)
REPEATED_ANNOTATION.registerFactory(RemoveAnnotationFix)
REPEATED_ANNOTATION_WARNING.registerFactory(RemoveAnnotationFix)
ACCIDENTAL_OVERRIDE.registerFactory(MakePrivateAndOverrideMemberFix.AccidentalOverrideFactory)
}
@@ -0,0 +1 @@
org.jetbrains.kotlin.idea.inspections.migration.ProhibitRepeatedUseSiteTargetAnnotationsMigrationInspection
@@ -0,0 +1,21 @@
// LANGUAGE_VERSION: 1.4
// DISABLE-ERRORS
annotation class Ann(val x: Int)
@get:Ann(10)<caret>
val a: String
@Ann(20) get() = "foo"
@set:Ann(10)
var b: String = ""
@Ann(20) set(value) { field = value }
@setparam:Ann(10)
var c = " "
set(@Ann(20) x) {}
@get:Ann(10)
@get:Ann(20)
val d: String
@Ann(30) @Ann(40) get() = "foo"
@@ -0,0 +1,20 @@
// LANGUAGE_VERSION: 1.4
// DISABLE-ERRORS
annotation class Ann(val x: Int)
val a: String
@Ann(20) get() = "foo"
@set:Ann(10)
var b: String = ""
@Ann(20) set(value) { field = value }
@setparam:Ann(10)
var c = " "
set(@Ann(20) x) {}
@get:Ann(10)
@get:Ann(20)
val d: String
@Ann(30) @Ann(40) get() = "foo"
@@ -0,0 +1,22 @@
// LANGUAGE_VERSION: 1.4
// DISABLE-ERRORS
// PROBLEM: none
annotation class Ann(val x: Int)
@get:Ann(10)
val a: String
@Ann(20)<caret> get() = "foo"
@set:Ann(10)
var b: String = ""
@Ann(20) set(value) { field = value }
@setparam:Ann(10)
var c = " "
set(@Ann(20) x) {}
@get:Ann(10)
@get:Ann(20)
val d: String
@Ann(30) @Ann(40) get() = "foo"
@@ -0,0 +1,21 @@
// LANGUAGE_VERSION: 1.4
// DISABLE-ERRORS
annotation class Ann(val x: Int)
@get:Ann(10)<caret>
val a: String
@Ann(20) get() = "foo"
@set:Ann(10)<caret>
var b: String = ""
@Ann(20) set(value) { field = value }
@setparam:Ann(10)
var c = " "
set(@Ann(20) x) {}
@get:Ann(10)
@get:Ann(20)
val d: String
@Ann(30) @Ann(40) get() = "foo"
@@ -0,0 +1,20 @@
// LANGUAGE_VERSION: 1.4
// DISABLE-ERRORS
annotation class Ann(val x: Int)
@get:Ann(10)
val a: String
@Ann(20) get() = "foo"
var b: String = ""
@Ann(20) set(value) { field = value }
@setparam:Ann(10)
var c = " "
set(@Ann(20) x) {}
@get:Ann(10)
@get:Ann(20)
val d: String
@Ann(30) @Ann(40) get() = "foo"
@@ -0,0 +1,21 @@
// LANGUAGE_VERSION: 1.4
// DISABLE-ERRORS
annotation class Ann(val x: Int)
@get:Ann(10)
val a: String
@Ann(20) get() = "foo"
@set:Ann(10)
var b: String = ""
@Ann(20) set(value) { field = value }
@setparam:Ann(10)<caret>
var c = " "
set(@Ann(20) x) {}
@get:Ann(10)
@get:Ann(20)
val d: String
@Ann(30) @Ann(40) get() = "foo"
@@ -0,0 +1,20 @@
// LANGUAGE_VERSION: 1.4
// DISABLE-ERRORS
annotation class Ann(val x: Int)
@get:Ann(10)
val a: String
@Ann(20) get() = "foo"
@set:Ann(10)
var b: String = ""
@Ann(20) set(value) { field = value }
var c = " "
set(@Ann(20) x) {}
@get:Ann(10)
@get:Ann(20)
val d: String
@Ann(30) @Ann(40) get() = "foo"
@@ -0,0 +1,21 @@
// LANGUAGE_VERSION: 1.4
// DISABLE-ERRORS
annotation class Ann(val x: Int)
@get:Ann(10)
val a: String
@Ann(20) get() = "foo"
@set:Ann(10)
var b: String = ""
@Ann(20) set(value) { field = value }
@setparam:Ann(10)
var c = " "
set(@Ann(20) x) {}
@get:Ann(10)
@get:Ann(20)
val d: String
@Ann(30) @Ann(40)<caret> get() = "foo"
@@ -0,0 +1,21 @@
// LANGUAGE_VERSION: 1.4
// DISABLE-ERRORS
annotation class Ann(val x: Int)
@get:Ann(10)
val a: String
@Ann(20) get() = "foo"
@set:Ann(10)
var b: String = ""
@Ann(20) set(value) { field = value }
@setparam:Ann(10)
var c = " "
set(@Ann(20) x) {}
@get:Ann(10)
@get:Ann(20)
val d: String
@Ann(30) get() = "foo"
@@ -0,0 +1,22 @@
// LANGUAGE_VERSION: 1.4
// DISABLE-ERRORS
// PROBLEM: none
annotation class Ann(val x: Int)
@get:Ann(10)<caret>
val a: String
@Ann(20) get() = "foo"
@set:Ann(10)
var b: String = ""
@Ann(20) set(value) { field = value }
@setparam:Ann(10)
var c = " "
set(@Ann(20) x) {}
@get:Ann(10)
@get:Ann(20)
val d: String
@Ann(30)<caret> @Ann(40) get() = "foo"
@@ -6621,6 +6621,49 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest {
}
}
@TestMetadata("idea/testData/inspectionsLocal/prohibitRepeatedUseSiteTargetAnnotationsMigration")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class ProhibitRepeatedUseSiteTargetAnnotationsMigration extends AbstractLocalInspectionTest {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
}
public void testAllFilesPresentInProhibitRepeatedUseSiteTargetAnnotationsMigration() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("idea/testData/inspectionsLocal/prohibitRepeatedUseSiteTargetAnnotationsMigration"), Pattern.compile("^([\\w\\-_]+)\\.(kt|kts)$"), null, true);
}
@TestMetadata("simple.kt")
public void testSimple() throws Exception {
runTest("idea/testData/inspectionsLocal/prohibitRepeatedUseSiteTargetAnnotationsMigration/simple.kt");
}
@TestMetadata("simple2.kt")
public void testSimple2() throws Exception {
runTest("idea/testData/inspectionsLocal/prohibitRepeatedUseSiteTargetAnnotationsMigration/simple2.kt");
}
@TestMetadata("simple3.kt")
public void testSimple3() throws Exception {
runTest("idea/testData/inspectionsLocal/prohibitRepeatedUseSiteTargetAnnotationsMigration/simple3.kt");
}
@TestMetadata("simple4.kt")
public void testSimple4() throws Exception {
runTest("idea/testData/inspectionsLocal/prohibitRepeatedUseSiteTargetAnnotationsMigration/simple4.kt");
}
@TestMetadata("simple5.kt")
public void testSimple5() throws Exception {
runTest("idea/testData/inspectionsLocal/prohibitRepeatedUseSiteTargetAnnotationsMigration/simple5.kt");
}
@TestMetadata("simple6.kt")
public void testSimple6() throws Exception {
runTest("idea/testData/inspectionsLocal/prohibitRepeatedUseSiteTargetAnnotationsMigration/simple6.kt");
}
}
@TestMetadata("idea/testData/inspectionsLocal/prohibitTypeParametersForLocalVariablesMigration")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)