Create ProhibitUseSiteTargetAnnotationsOnSuperTypesMigrationInspection
#KT-36258 Fixed
This commit is contained in:
@@ -3159,6 +3159,16 @@
|
|||||||
language="kotlin"
|
language="kotlin"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<localInspection implementationClass="org.jetbrains.kotlin.idea.inspections.migration.ProhibitUseSiteTargetAnnotationsOnSuperTypesMigrationInspection"
|
||||||
|
displayName="Annotations on superclass are meaningless since 1.4"
|
||||||
|
groupPath="Kotlin"
|
||||||
|
groupName="Migration"
|
||||||
|
enabledByDefault="false"
|
||||||
|
cleanupTool="true"
|
||||||
|
level="ERROR"
|
||||||
|
language="kotlin"
|
||||||
|
/>
|
||||||
|
|
||||||
<localInspection implementationClass="org.jetbrains.kotlin.idea.inspections.migration.ObsoleteExperimentalCoroutinesInspection"
|
<localInspection implementationClass="org.jetbrains.kotlin.idea.inspections.migration.ObsoleteExperimentalCoroutinesInspection"
|
||||||
displayName="Experimental coroutines usages are deprecated since 1.3"
|
displayName="Experimental coroutines usages are deprecated since 1.3"
|
||||||
groupPath="Kotlin"
|
groupPath="Kotlin"
|
||||||
|
|||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
<html>
|
||||||
|
<body>
|
||||||
|
Since Kotlin 1.4, annotations on superclass are meaningless.
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
* 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.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -13,12 +13,12 @@ import org.jetbrains.kotlin.idea.quickfix.KotlinSingleIntentionActionFactory
|
|||||||
import org.jetbrains.kotlin.psi.KtAnnotationEntry
|
import org.jetbrains.kotlin.psi.KtAnnotationEntry
|
||||||
import org.jetbrains.kotlin.psi.KtFile
|
import org.jetbrains.kotlin.psi.KtFile
|
||||||
|
|
||||||
class RemoveAnnotationFix(private val name: String, annotationEntry: KtAnnotationEntry) :
|
class RemoveAnnotationFix(private val text: String = "Remove annotation", annotationEntry: KtAnnotationEntry) :
|
||||||
KotlinQuickFixAction<KtAnnotationEntry>(annotationEntry) {
|
KotlinQuickFixAction<KtAnnotationEntry>(annotationEntry) {
|
||||||
|
|
||||||
override fun getText() = name
|
override fun getText() = text
|
||||||
|
|
||||||
override fun getFamilyName() = name
|
override fun getFamilyName() = text
|
||||||
|
|
||||||
override fun invoke(project: Project, editor: Editor?, file: KtFile) {
|
override fun invoke(project: Project, editor: Editor?, file: KtFile) {
|
||||||
element?.delete()
|
element?.delete()
|
||||||
@@ -30,4 +30,11 @@ class RemoveAnnotationFix(private val name: String, annotationEntry: KtAnnotatio
|
|||||||
return RemoveAnnotationFix("Remove @JvmOverloads annotation", annotationEntry)
|
return RemoveAnnotationFix("Remove @JvmOverloads annotation", annotationEntry)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
companion object : KotlinSingleIntentionActionFactory() {
|
||||||
|
override fun createAction(diagnostic: Diagnostic): RemoveAnnotationFix? {
|
||||||
|
val annotationEntry = diagnostic.psiElement as? KtAnnotationEntry ?: return null
|
||||||
|
return RemoveAnnotationFix(annotationEntry = annotationEntry)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+25
@@ -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 ProhibitUseSiteTargetAnnotationsOnSuperTypesMigrationInspection :
|
||||||
|
AbstractDiagnosticBasedMigrationInspection<KtAnnotationEntry>(Errors.ANNOTATION_ON_SUPERCLASS, KtAnnotationEntry::class.java),
|
||||||
|
MigrationFix,
|
||||||
|
CleanupLocalInspectionTool {
|
||||||
|
override fun isApplicable(migrationInfo: MigrationInfo): Boolean {
|
||||||
|
return migrationInfo.isLanguageVersionUpdate(LanguageVersion.KOTLIN_1_3, LanguageVersion.KOTLIN_1_4)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -630,6 +630,9 @@ class QuickFixRegistrar : QuickFixContributor {
|
|||||||
NOT_A_FUNCTION_LABEL.registerFactory(RemoveReturnLabelFix)
|
NOT_A_FUNCTION_LABEL.registerFactory(RemoveReturnLabelFix)
|
||||||
NOT_A_FUNCTION_LABEL_WARNING.registerFactory(RemoveReturnLabelFix)
|
NOT_A_FUNCTION_LABEL_WARNING.registerFactory(RemoveReturnLabelFix)
|
||||||
|
|
||||||
|
ANNOTATION_ON_SUPERCLASS.registerFactory(RemoveAnnotationFix)
|
||||||
|
ANNOTATION_ON_SUPERCLASS_WARNING.registerFactory(RemoveAnnotationFix)
|
||||||
|
|
||||||
ACCIDENTAL_OVERRIDE.registerFactory(MakePrivateAndOverrideMemberFix.AccidentalOverrideFactory)
|
ACCIDENTAL_OVERRIDE.registerFactory(MakePrivateAndOverrideMemberFix.AccidentalOverrideFactory)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+1
@@ -0,0 +1 @@
|
|||||||
|
org.jetbrains.kotlin.idea.inspections.migration.ProhibitUseSiteTargetAnnotationsOnSuperTypesMigrationInspection
|
||||||
Vendored
+10
@@ -0,0 +1,10 @@
|
|||||||
|
// LANGUAGE_VERSION: 1.4
|
||||||
|
// DISABLE-ERRORS
|
||||||
|
|
||||||
|
interface Foo
|
||||||
|
|
||||||
|
annotation class Ann
|
||||||
|
|
||||||
|
class E : <caret>@field:Ann @get:Ann @set:Ann @setparam:Ann Foo
|
||||||
|
|
||||||
|
interface G : @Ann Foo
|
||||||
idea/testData/inspectionsLocal/prohibitUseSiteTargetAnnotationsOnSuperTypesMigration/simple.kt.after
Vendored
+10
@@ -0,0 +1,10 @@
|
|||||||
|
// LANGUAGE_VERSION: 1.4
|
||||||
|
// DISABLE-ERRORS
|
||||||
|
|
||||||
|
interface Foo
|
||||||
|
|
||||||
|
annotation class Ann
|
||||||
|
|
||||||
|
class E : @get:Ann @set:Ann @setparam:Ann Foo
|
||||||
|
|
||||||
|
interface G : @Ann Foo
|
||||||
Vendored
+10
@@ -0,0 +1,10 @@
|
|||||||
|
// LANGUAGE_VERSION: 1.4
|
||||||
|
// DISABLE-ERRORS
|
||||||
|
|
||||||
|
interface Foo
|
||||||
|
|
||||||
|
annotation class Ann
|
||||||
|
|
||||||
|
class E : @field:Ann <caret>@get:Ann @set:Ann @setparam:Ann Foo
|
||||||
|
|
||||||
|
interface G : @Ann Foo
|
||||||
+10
@@ -0,0 +1,10 @@
|
|||||||
|
// LANGUAGE_VERSION: 1.4
|
||||||
|
// DISABLE-ERRORS
|
||||||
|
|
||||||
|
interface Foo
|
||||||
|
|
||||||
|
annotation class Ann
|
||||||
|
|
||||||
|
class E : @field:Ann @set:Ann @setparam:Ann Foo
|
||||||
|
|
||||||
|
interface G : @Ann Foo
|
||||||
Vendored
+10
@@ -0,0 +1,10 @@
|
|||||||
|
// LANGUAGE_VERSION: 1.4
|
||||||
|
// DISABLE-ERRORS
|
||||||
|
|
||||||
|
interface Foo
|
||||||
|
|
||||||
|
annotation class Ann
|
||||||
|
|
||||||
|
class E : @field:Ann @get:Ann <caret>@set:Ann @setparam:Ann Foo
|
||||||
|
|
||||||
|
interface G : @Ann Foo
|
||||||
+10
@@ -0,0 +1,10 @@
|
|||||||
|
// LANGUAGE_VERSION: 1.4
|
||||||
|
// DISABLE-ERRORS
|
||||||
|
|
||||||
|
interface Foo
|
||||||
|
|
||||||
|
annotation class Ann
|
||||||
|
|
||||||
|
class E : @field:Ann @get:Ann @setparam:Ann Foo
|
||||||
|
|
||||||
|
interface G : @Ann Foo
|
||||||
Vendored
+10
@@ -0,0 +1,10 @@
|
|||||||
|
// LANGUAGE_VERSION: 1.4
|
||||||
|
// DISABLE-ERRORS
|
||||||
|
|
||||||
|
interface Foo
|
||||||
|
|
||||||
|
annotation class Ann
|
||||||
|
|
||||||
|
class E : @field:Ann @get:Ann @set:Ann <caret>@setparam:Ann Foo
|
||||||
|
|
||||||
|
interface G : @Ann Foo
|
||||||
+10
@@ -0,0 +1,10 @@
|
|||||||
|
// LANGUAGE_VERSION: 1.4
|
||||||
|
// DISABLE-ERRORS
|
||||||
|
|
||||||
|
interface Foo
|
||||||
|
|
||||||
|
annotation class Ann
|
||||||
|
|
||||||
|
class E : @field:Ann @get:Ann @set:Ann Foo
|
||||||
|
|
||||||
|
interface G : @Ann Foo
|
||||||
Vendored
+11
@@ -0,0 +1,11 @@
|
|||||||
|
// LANGUAGE_VERSION: 1.4
|
||||||
|
// PROBLEM: none
|
||||||
|
// DISABLE-ERRORS
|
||||||
|
|
||||||
|
interface Foo
|
||||||
|
|
||||||
|
annotation class Ann
|
||||||
|
|
||||||
|
class E : @field:Ann @get:Ann @set:Ann @setparam:Ann Foo
|
||||||
|
|
||||||
|
interface G : <caret>@Ann Foo
|
||||||
+38
@@ -6639,6 +6639,44 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("idea/testData/inspectionsLocal/prohibitUseSiteTargetAnnotationsOnSuperTypesMigration")
|
||||||
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
|
public static class ProhibitUseSiteTargetAnnotationsOnSuperTypesMigration extends AbstractLocalInspectionTest {
|
||||||
|
private void runTest(String testDataFilePath) throws Exception {
|
||||||
|
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testAllFilesPresentInProhibitUseSiteTargetAnnotationsOnSuperTypesMigration() throws Exception {
|
||||||
|
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("idea/testData/inspectionsLocal/prohibitUseSiteTargetAnnotationsOnSuperTypesMigration"), Pattern.compile("^([\\w\\-_]+)\\.(kt|kts)$"), null, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("simple.kt")
|
||||||
|
public void testSimple() throws Exception {
|
||||||
|
runTest("idea/testData/inspectionsLocal/prohibitUseSiteTargetAnnotationsOnSuperTypesMigration/simple.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("simple2.kt")
|
||||||
|
public void testSimple2() throws Exception {
|
||||||
|
runTest("idea/testData/inspectionsLocal/prohibitUseSiteTargetAnnotationsOnSuperTypesMigration/simple2.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("simple3.kt")
|
||||||
|
public void testSimple3() throws Exception {
|
||||||
|
runTest("idea/testData/inspectionsLocal/prohibitUseSiteTargetAnnotationsOnSuperTypesMigration/simple3.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("simple4.kt")
|
||||||
|
public void testSimple4() throws Exception {
|
||||||
|
runTest("idea/testData/inspectionsLocal/prohibitUseSiteTargetAnnotationsOnSuperTypesMigration/simple4.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("simple5.kt")
|
||||||
|
public void testSimple5() throws Exception {
|
||||||
|
runTest("idea/testData/inspectionsLocal/prohibitUseSiteTargetAnnotationsOnSuperTypesMigration/simple5.kt");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("idea/testData/inspectionsLocal/recursiveEqualsCall")
|
@TestMetadata("idea/testData/inspectionsLocal/recursiveEqualsCall")
|
||||||
@TestDataPath("$PROJECT_ROOT")
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
@RunWith(JUnit3RunnerWithInners.class)
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
|
|||||||
Reference in New Issue
Block a user