diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/QuickFixRegistrar.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/QuickFixRegistrar.kt index aebbf7871e2..12b0ce685c6 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/QuickFixRegistrar.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/QuickFixRegistrar.kt @@ -607,5 +607,8 @@ class QuickFixRegistrar : QuickFixContributor { MUST_BE_INITIALIZED_OR_BE_ABSTRACT.registerFactory(AbstractAddAccessorsIntention) MUST_BE_INITIALIZED.registerFactory(AbstractAddAccessorsIntention) + + RESTRICTED_RETENTION_FOR_EXPRESSION_ANNOTATION.registerFactory(RestrictedRetentionForExpressionAnnotationFactory) + RESTRICTED_RETENTION_FOR_EXPRESSION_ANNOTATION_WARNING.registerFactory(RestrictedRetentionForExpressionAnnotationFactory) } } diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/RestrictedRetentionForExpressionAnnotationFactory.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/RestrictedRetentionForExpressionAnnotationFactory.kt new file mode 100644 index 00000000000..288b5cce8fd --- /dev/null +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/RestrictedRetentionForExpressionAnnotationFactory.kt @@ -0,0 +1,86 @@ +/* + * Copyright 2010-2018 JetBrains s.r.o. 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.quickfix + +import com.intellij.codeInsight.intention.IntentionAction +import com.intellij.openapi.editor.Editor +import com.intellij.openapi.project.Project +import org.jetbrains.kotlin.builtins.KotlinBuiltIns +import org.jetbrains.kotlin.diagnostics.Diagnostic +import org.jetbrains.kotlin.idea.caches.resolve.analyze +import org.jetbrains.kotlin.idea.core.ShortenReferences +import org.jetbrains.kotlin.name.FqName +import org.jetbrains.kotlin.psi.* +import org.jetbrains.kotlin.psi.psiUtil.containingClass +import org.jetbrains.kotlin.resolve.BindingContext +import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe + +object RestrictedRetentionForExpressionAnnotationFactory : KotlinIntentionActionsFactory() { + + private val sourceRetention = "${KotlinBuiltIns.FQ_NAMES.annotationRetention.asString()}.${AnnotationRetention.SOURCE.name}" + private val sourceRetentionAnnotation = "@${KotlinBuiltIns.FQ_NAMES.retention.asString()}($sourceRetention)" + + override fun doCreateActions(diagnostic: Diagnostic): List { + val annotationEntry = diagnostic.psiElement as? KtAnnotationEntry ?: return emptyList() + val containingClass = annotationEntry.containingClass() ?: return emptyList() + val retentionAnnotation = containingClass.annotation(KotlinBuiltIns.FQ_NAMES.retention) + return listOf( + RemoveExpressionTargetFix(containingClass), + if (retentionAnnotation == null) AddSourceRetentionFix(containingClass) else ChangeRetentionToSourceFix(containingClass) + ) + } + + private fun KtClass.annotation(fqName: FqName): KtAnnotationEntry? { + return annotationEntries.firstOrNull { + it.typeReference?.text?.endsWith(fqName.shortName().asString()) == true + && analyze()[BindingContext.TYPE, it.typeReference]?.constructor?.declarationDescriptor?.fqNameSafe == fqName + } + } + + private class AddSourceRetentionFix(element: KtClass) : KotlinQuickFixAction(element) { + override fun getText() = "Add SOURCE retention" + + override fun getFamilyName() = text + + override fun invoke(project: Project, editor: Editor?, file: KtFile) { + val element = element ?: return + val added = element.addAnnotationEntry(KtPsiFactory(element).createAnnotationEntry(sourceRetentionAnnotation)) + ShortenReferences.DEFAULT.process(added) + } + } + + private class ChangeRetentionToSourceFix(element: KtClass) : KotlinQuickFixAction(element) { + override fun getText() = "Change existent retention to SOURCE" + + override fun getFamilyName() = text + + override fun invoke(project: Project, editor: Editor?, file: KtFile) { + val retentionAnnotation = element?.annotation(KotlinBuiltIns.FQ_NAMES.retention) ?: return + val psiFactory = KtPsiFactory(retentionAnnotation) + val added = if (retentionAnnotation.valueArgumentList == null) { + retentionAnnotation.add(psiFactory.createCallArguments("($sourceRetention)")) as KtValueArgumentList + } else { + if (retentionAnnotation.valueArguments.isNotEmpty()) { + retentionAnnotation.valueArgumentList?.removeArgument(0) + } + retentionAnnotation.valueArgumentList?.addArgument(psiFactory.createArgument(sourceRetention)) + } + if (added != null) { + ShortenReferences.DEFAULT.process(added) + } + } + } + + private class RemoveExpressionTargetFix(element: KtClass) : KotlinQuickFixAction(element) { + override fun getText() = "Remove EXPRESSION target" + + override fun getFamilyName() = text + + override fun invoke(project: Project, editor: Editor?, file: KtFile) { + element?.annotation(KotlinBuiltIns.FQ_NAMES.target)?.delete() + } + } +} \ No newline at end of file diff --git a/idea/testData/quickfix/restrictedRetentionForExpressionAnnotation/addSourceRetention/binaryRetention.kt b/idea/testData/quickfix/restrictedRetentionForExpressionAnnotation/addSourceRetention/binaryRetention.kt new file mode 100644 index 00000000000..d41076109c2 --- /dev/null +++ b/idea/testData/quickfix/restrictedRetentionForExpressionAnnotation/addSourceRetention/binaryRetention.kt @@ -0,0 +1,9 @@ +// "Add SOURCE retention" "false" +// DISABLE-ERRORS +// ACTION: Change existent retention to SOURCE +// ACTION: Make internal +// ACTION: Make private +// ACTION: Remove EXPRESSION target +@Retention(AnnotationRetention.BINARY) +@Target(AnnotationTarget.EXPRESSION) +annotation class Ann \ No newline at end of file diff --git a/idea/testData/quickfix/restrictedRetentionForExpressionAnnotation/addSourceRetention/emptyRetention.kt b/idea/testData/quickfix/restrictedRetentionForExpressionAnnotation/addSourceRetention/emptyRetention.kt new file mode 100644 index 00000000000..6ed75a3790f --- /dev/null +++ b/idea/testData/quickfix/restrictedRetentionForExpressionAnnotation/addSourceRetention/emptyRetention.kt @@ -0,0 +1,9 @@ +// "Add SOURCE retention" "false" +// DISABLE-ERRORS +// ACTION: Change existent retention to SOURCE +// ACTION: Make internal +// ACTION: Make private +// ACTION: Remove EXPRESSION target +@Retention +@Target(AnnotationTarget.EXPRESSION) +annotation class Ann \ No newline at end of file diff --git a/idea/testData/quickfix/restrictedRetentionForExpressionAnnotation/addSourceRetention/emptyRetention2.kt b/idea/testData/quickfix/restrictedRetentionForExpressionAnnotation/addSourceRetention/emptyRetention2.kt new file mode 100644 index 00000000000..2d90607950a --- /dev/null +++ b/idea/testData/quickfix/restrictedRetentionForExpressionAnnotation/addSourceRetention/emptyRetention2.kt @@ -0,0 +1,9 @@ +// "Add SOURCE retention" "false" +// DISABLE-ERRORS +// ACTION: Change existent retention to SOURCE +// ACTION: Make internal +// ACTION: Make private +// ACTION: Remove EXPRESSION target +@Retention() +@Target(AnnotationTarget.EXPRESSION) +annotation class Ann \ No newline at end of file diff --git a/idea/testData/quickfix/restrictedRetentionForExpressionAnnotation/addSourceRetention/noRetention.kt b/idea/testData/quickfix/restrictedRetentionForExpressionAnnotation/addSourceRetention/noRetention.kt new file mode 100644 index 00000000000..971f2b34819 --- /dev/null +++ b/idea/testData/quickfix/restrictedRetentionForExpressionAnnotation/addSourceRetention/noRetention.kt @@ -0,0 +1,3 @@ +// "Add SOURCE retention" "true" +@Target(AnnotationTarget.EXPRESSION) +annotation class Ann \ No newline at end of file diff --git a/idea/testData/quickfix/restrictedRetentionForExpressionAnnotation/addSourceRetention/noRetention.kt.after b/idea/testData/quickfix/restrictedRetentionForExpressionAnnotation/addSourceRetention/noRetention.kt.after new file mode 100644 index 00000000000..ef5c9e42e68 --- /dev/null +++ b/idea/testData/quickfix/restrictedRetentionForExpressionAnnotation/addSourceRetention/noRetention.kt.after @@ -0,0 +1,4 @@ +// "Add SOURCE retention" "true" +@Retention(AnnotationRetention.SOURCE) +@Target(AnnotationTarget.EXPRESSION) +annotation class Ann \ No newline at end of file diff --git a/idea/testData/quickfix/restrictedRetentionForExpressionAnnotation/addSourceRetention/noRetention2.kt b/idea/testData/quickfix/restrictedRetentionForExpressionAnnotation/addSourceRetention/noRetention2.kt new file mode 100644 index 00000000000..74a312c5ec6 --- /dev/null +++ b/idea/testData/quickfix/restrictedRetentionForExpressionAnnotation/addSourceRetention/noRetention2.kt @@ -0,0 +1,6 @@ +// "Add SOURCE retention" "true" +annotation class Retention + +@Retention +@Target(AnnotationTarget.EXPRESSION) +annotation class Ann \ No newline at end of file diff --git a/idea/testData/quickfix/restrictedRetentionForExpressionAnnotation/addSourceRetention/noRetention2.kt.after b/idea/testData/quickfix/restrictedRetentionForExpressionAnnotation/addSourceRetention/noRetention2.kt.after new file mode 100644 index 00000000000..fd2a1d4eff6 --- /dev/null +++ b/idea/testData/quickfix/restrictedRetentionForExpressionAnnotation/addSourceRetention/noRetention2.kt.after @@ -0,0 +1,7 @@ +// "Add SOURCE retention" "true" +annotation class Retention + +@kotlin.annotation.Retention(AnnotationRetention.SOURCE) +@Retention +@Target(AnnotationTarget.EXPRESSION) +annotation class Ann \ No newline at end of file diff --git a/idea/testData/quickfix/restrictedRetentionForExpressionAnnotation/changeRetentionToSource/binaryRetention.kt b/idea/testData/quickfix/restrictedRetentionForExpressionAnnotation/changeRetentionToSource/binaryRetention.kt new file mode 100644 index 00000000000..434b1a69013 --- /dev/null +++ b/idea/testData/quickfix/restrictedRetentionForExpressionAnnotation/changeRetentionToSource/binaryRetention.kt @@ -0,0 +1,4 @@ +// "Change existent retention to SOURCE" "true" +@Retention(AnnotationRetention.BINARY) +@Target(AnnotationTarget.EXPRESSION) +annotation class Ann \ No newline at end of file diff --git a/idea/testData/quickfix/restrictedRetentionForExpressionAnnotation/changeRetentionToSource/binaryRetention.kt.after b/idea/testData/quickfix/restrictedRetentionForExpressionAnnotation/changeRetentionToSource/binaryRetention.kt.after new file mode 100644 index 00000000000..853c5e60e97 --- /dev/null +++ b/idea/testData/quickfix/restrictedRetentionForExpressionAnnotation/changeRetentionToSource/binaryRetention.kt.after @@ -0,0 +1,4 @@ +// "Change existent retention to SOURCE" "true" +@Retention(AnnotationRetention.SOURCE) +@Target(AnnotationTarget.EXPRESSION) +annotation class Ann \ No newline at end of file diff --git a/idea/testData/quickfix/restrictedRetentionForExpressionAnnotation/changeRetentionToSource/emptyRetention.kt b/idea/testData/quickfix/restrictedRetentionForExpressionAnnotation/changeRetentionToSource/emptyRetention.kt new file mode 100644 index 00000000000..21f8ed17de0 --- /dev/null +++ b/idea/testData/quickfix/restrictedRetentionForExpressionAnnotation/changeRetentionToSource/emptyRetention.kt @@ -0,0 +1,4 @@ +// "Change existent retention to SOURCE" "true" +@Retention +@Target(AnnotationTarget.EXPRESSION) +annotation class Ann \ No newline at end of file diff --git a/idea/testData/quickfix/restrictedRetentionForExpressionAnnotation/changeRetentionToSource/emptyRetention.kt.after b/idea/testData/quickfix/restrictedRetentionForExpressionAnnotation/changeRetentionToSource/emptyRetention.kt.after new file mode 100644 index 00000000000..853c5e60e97 --- /dev/null +++ b/idea/testData/quickfix/restrictedRetentionForExpressionAnnotation/changeRetentionToSource/emptyRetention.kt.after @@ -0,0 +1,4 @@ +// "Change existent retention to SOURCE" "true" +@Retention(AnnotationRetention.SOURCE) +@Target(AnnotationTarget.EXPRESSION) +annotation class Ann \ No newline at end of file diff --git a/idea/testData/quickfix/restrictedRetentionForExpressionAnnotation/changeRetentionToSource/emptyRetention2.kt b/idea/testData/quickfix/restrictedRetentionForExpressionAnnotation/changeRetentionToSource/emptyRetention2.kt new file mode 100644 index 00000000000..50ce5a0b72d --- /dev/null +++ b/idea/testData/quickfix/restrictedRetentionForExpressionAnnotation/changeRetentionToSource/emptyRetention2.kt @@ -0,0 +1,4 @@ +// "Change existent retention to SOURCE" "true" +@Retention() +@Target(AnnotationTarget.EXPRESSION) +annotation class Ann \ No newline at end of file diff --git a/idea/testData/quickfix/restrictedRetentionForExpressionAnnotation/changeRetentionToSource/emptyRetention2.kt.after b/idea/testData/quickfix/restrictedRetentionForExpressionAnnotation/changeRetentionToSource/emptyRetention2.kt.after new file mode 100644 index 00000000000..853c5e60e97 --- /dev/null +++ b/idea/testData/quickfix/restrictedRetentionForExpressionAnnotation/changeRetentionToSource/emptyRetention2.kt.after @@ -0,0 +1,4 @@ +// "Change existent retention to SOURCE" "true" +@Retention(AnnotationRetention.SOURCE) +@Target(AnnotationTarget.EXPRESSION) +annotation class Ann \ No newline at end of file diff --git a/idea/testData/quickfix/restrictedRetentionForExpressionAnnotation/changeRetentionToSource/emptyRetention3.kt b/idea/testData/quickfix/restrictedRetentionForExpressionAnnotation/changeRetentionToSource/emptyRetention3.kt new file mode 100644 index 00000000000..cd5abed3676 --- /dev/null +++ b/idea/testData/quickfix/restrictedRetentionForExpressionAnnotation/changeRetentionToSource/emptyRetention3.kt @@ -0,0 +1,6 @@ +// "Change existent retention to SOURCE" "true" +class AnnotationRetention + +@Retention() +@Target(AnnotationTarget.EXPRESSION) +annotation class Ann \ No newline at end of file diff --git a/idea/testData/quickfix/restrictedRetentionForExpressionAnnotation/changeRetentionToSource/emptyRetention3.kt.after b/idea/testData/quickfix/restrictedRetentionForExpressionAnnotation/changeRetentionToSource/emptyRetention3.kt.after new file mode 100644 index 00000000000..bb0cd8cd9e9 --- /dev/null +++ b/idea/testData/quickfix/restrictedRetentionForExpressionAnnotation/changeRetentionToSource/emptyRetention3.kt.after @@ -0,0 +1,8 @@ +import kotlin.annotation.AnnotationRetention + +// "Change existent retention to SOURCE" "true" +class AnnotationRetention + +@Retention(AnnotationRetention.SOURCE) +@Target(AnnotationTarget.EXPRESSION) +annotation class Ann \ No newline at end of file diff --git a/idea/testData/quickfix/restrictedRetentionForExpressionAnnotation/changeRetentionToSource/noRetention.kt b/idea/testData/quickfix/restrictedRetentionForExpressionAnnotation/changeRetentionToSource/noRetention.kt new file mode 100644 index 00000000000..5668b209df1 --- /dev/null +++ b/idea/testData/quickfix/restrictedRetentionForExpressionAnnotation/changeRetentionToSource/noRetention.kt @@ -0,0 +1,8 @@ +// "Change existent retention to SOURCE" "false" +// DISABLE-ERRORS +// ACTION: Add SOURCE retention +// ACTION: Make internal +// ACTION: Make private +// ACTION: Remove EXPRESSION target +@Target(AnnotationTarget.EXPRESSION) +annotation class Ann \ No newline at end of file diff --git a/idea/testData/quickfix/restrictedRetentionForExpressionAnnotation/removeExpressionTarget/binaryRetention.kt b/idea/testData/quickfix/restrictedRetentionForExpressionAnnotation/removeExpressionTarget/binaryRetention.kt new file mode 100644 index 00000000000..2232213318f --- /dev/null +++ b/idea/testData/quickfix/restrictedRetentionForExpressionAnnotation/removeExpressionTarget/binaryRetention.kt @@ -0,0 +1,4 @@ +// "Remove EXPRESSION target" "true" +@Retention(AnnotationRetention.BINARY) +@Target(AnnotationTarget.EXPRESSION) +annotation class Ann \ No newline at end of file diff --git a/idea/testData/quickfix/restrictedRetentionForExpressionAnnotation/removeExpressionTarget/binaryRetention.kt.after b/idea/testData/quickfix/restrictedRetentionForExpressionAnnotation/removeExpressionTarget/binaryRetention.kt.after new file mode 100644 index 00000000000..1e92cc42a7f --- /dev/null +++ b/idea/testData/quickfix/restrictedRetentionForExpressionAnnotation/removeExpressionTarget/binaryRetention.kt.after @@ -0,0 +1,3 @@ +// "Remove EXPRESSION target" "true" +@Retention(AnnotationRetention.BINARY) +annotation class Ann \ No newline at end of file diff --git a/idea/testData/quickfix/restrictedRetentionForExpressionAnnotation/removeExpressionTarget/emptyRetention.kt b/idea/testData/quickfix/restrictedRetentionForExpressionAnnotation/removeExpressionTarget/emptyRetention.kt new file mode 100644 index 00000000000..11fcd837ac7 --- /dev/null +++ b/idea/testData/quickfix/restrictedRetentionForExpressionAnnotation/removeExpressionTarget/emptyRetention.kt @@ -0,0 +1,4 @@ +// "Remove EXPRESSION target" "true" +@Retention +@Target(AnnotationTarget.EXPRESSION) +annotation class Ann \ No newline at end of file diff --git a/idea/testData/quickfix/restrictedRetentionForExpressionAnnotation/removeExpressionTarget/emptyRetention.kt.after b/idea/testData/quickfix/restrictedRetentionForExpressionAnnotation/removeExpressionTarget/emptyRetention.kt.after new file mode 100644 index 00000000000..81ab769ea5c --- /dev/null +++ b/idea/testData/quickfix/restrictedRetentionForExpressionAnnotation/removeExpressionTarget/emptyRetention.kt.after @@ -0,0 +1,3 @@ +// "Remove EXPRESSION target" "true" +@Retention +annotation class Ann \ No newline at end of file diff --git a/idea/testData/quickfix/restrictedRetentionForExpressionAnnotation/removeExpressionTarget/emptyRetention2.kt b/idea/testData/quickfix/restrictedRetentionForExpressionAnnotation/removeExpressionTarget/emptyRetention2.kt new file mode 100644 index 00000000000..e3e94cb0408 --- /dev/null +++ b/idea/testData/quickfix/restrictedRetentionForExpressionAnnotation/removeExpressionTarget/emptyRetention2.kt @@ -0,0 +1,4 @@ +// "Remove EXPRESSION target" "true" +@Retention() +@Target(AnnotationTarget.EXPRESSION) +annotation class Ann \ No newline at end of file diff --git a/idea/testData/quickfix/restrictedRetentionForExpressionAnnotation/removeExpressionTarget/emptyRetention2.kt.after b/idea/testData/quickfix/restrictedRetentionForExpressionAnnotation/removeExpressionTarget/emptyRetention2.kt.after new file mode 100644 index 00000000000..c6702be45fc --- /dev/null +++ b/idea/testData/quickfix/restrictedRetentionForExpressionAnnotation/removeExpressionTarget/emptyRetention2.kt.after @@ -0,0 +1,3 @@ +// "Remove EXPRESSION target" "true" +@Retention() +annotation class Ann \ No newline at end of file diff --git a/idea/testData/quickfix/restrictedRetentionForExpressionAnnotation/removeExpressionTarget/noRetention.kt b/idea/testData/quickfix/restrictedRetentionForExpressionAnnotation/removeExpressionTarget/noRetention.kt new file mode 100644 index 00000000000..26a647781b9 --- /dev/null +++ b/idea/testData/quickfix/restrictedRetentionForExpressionAnnotation/removeExpressionTarget/noRetention.kt @@ -0,0 +1,3 @@ +// "Remove EXPRESSION target" "true" +@Target(AnnotationTarget.EXPRESSION) +annotation class Ann \ No newline at end of file diff --git a/idea/testData/quickfix/restrictedRetentionForExpressionAnnotation/removeExpressionTarget/noRetention.kt.after b/idea/testData/quickfix/restrictedRetentionForExpressionAnnotation/removeExpressionTarget/noRetention.kt.after new file mode 100644 index 00000000000..651d39dd051 --- /dev/null +++ b/idea/testData/quickfix/restrictedRetentionForExpressionAnnotation/removeExpressionTarget/noRetention.kt.after @@ -0,0 +1,2 @@ +// "Remove EXPRESSION target" "true" +annotation class Ann \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixMultiFileTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixMultiFileTestGenerated.java index ab20cc68312..e03262a866a 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixMultiFileTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixMultiFileTestGenerated.java @@ -3885,6 +3885,58 @@ public class QuickFixMultiFileTestGenerated extends AbstractQuickFixMultiFileTes } } + @TestMetadata("idea/testData/quickfix/restrictedRetentionForExpressionAnnotation") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class RestrictedRetentionForExpressionAnnotation extends AbstractQuickFixMultiFileTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTestWithExtraFile, TargetBackend.ANY, testDataFilePath); + } + + public void testAllFilesPresentInRestrictedRetentionForExpressionAnnotation() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/quickfix/restrictedRetentionForExpressionAnnotation"), Pattern.compile("^(\\w+)\\.((before\\.Main\\.\\w+)|(test))$"), TargetBackend.ANY, true); + } + + @TestMetadata("idea/testData/quickfix/restrictedRetentionForExpressionAnnotation/addSourceRetention") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class AddSourceRetention extends AbstractQuickFixMultiFileTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTestWithExtraFile, TargetBackend.ANY, testDataFilePath); + } + + public void testAllFilesPresentInAddSourceRetention() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/quickfix/restrictedRetentionForExpressionAnnotation/addSourceRetention"), Pattern.compile("^(\\w+)\\.((before\\.Main\\.\\w+)|(test))$"), TargetBackend.ANY, true); + } + } + + @TestMetadata("idea/testData/quickfix/restrictedRetentionForExpressionAnnotation/changeRetentionToSource") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class ChangeRetentionToSource extends AbstractQuickFixMultiFileTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTestWithExtraFile, TargetBackend.ANY, testDataFilePath); + } + + public void testAllFilesPresentInChangeRetentionToSource() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/quickfix/restrictedRetentionForExpressionAnnotation/changeRetentionToSource"), Pattern.compile("^(\\w+)\\.((before\\.Main\\.\\w+)|(test))$"), TargetBackend.ANY, true); + } + } + + @TestMetadata("idea/testData/quickfix/restrictedRetentionForExpressionAnnotation/removeExpressionTarget") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class RemoveExpressionTarget extends AbstractQuickFixMultiFileTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTestWithExtraFile, TargetBackend.ANY, testDataFilePath); + } + + public void testAllFilesPresentInRemoveExpressionTarget() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/quickfix/restrictedRetentionForExpressionAnnotation/removeExpressionTarget"), Pattern.compile("^(\\w+)\\.((before\\.Main\\.\\w+)|(test))$"), TargetBackend.ANY, true); + } + } + } + @TestMetadata("idea/testData/quickfix/simplifyComparison") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java index a3a43a0802a..79aa624baeb 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java @@ -10855,6 +10855,128 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest { } } + @TestMetadata("idea/testData/quickfix/restrictedRetentionForExpressionAnnotation") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class RestrictedRetentionForExpressionAnnotation extends AbstractQuickFixTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, TargetBackend.ANY, testDataFilePath); + } + + public void testAllFilesPresentInRestrictedRetentionForExpressionAnnotation() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/quickfix/restrictedRetentionForExpressionAnnotation"), Pattern.compile("^([\\w\\-_]+)\\.kt$"), TargetBackend.ANY, true); + } + + @TestMetadata("idea/testData/quickfix/restrictedRetentionForExpressionAnnotation/addSourceRetention") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class AddSourceRetention extends AbstractQuickFixTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, TargetBackend.ANY, testDataFilePath); + } + + public void testAllFilesPresentInAddSourceRetention() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/quickfix/restrictedRetentionForExpressionAnnotation/addSourceRetention"), Pattern.compile("^([\\w\\-_]+)\\.kt$"), TargetBackend.ANY, true); + } + + @TestMetadata("binaryRetention.kt") + public void testBinaryRetention() throws Exception { + runTest("idea/testData/quickfix/restrictedRetentionForExpressionAnnotation/addSourceRetention/binaryRetention.kt"); + } + + @TestMetadata("emptyRetention.kt") + public void testEmptyRetention() throws Exception { + runTest("idea/testData/quickfix/restrictedRetentionForExpressionAnnotation/addSourceRetention/emptyRetention.kt"); + } + + @TestMetadata("emptyRetention2.kt") + public void testEmptyRetention2() throws Exception { + runTest("idea/testData/quickfix/restrictedRetentionForExpressionAnnotation/addSourceRetention/emptyRetention2.kt"); + } + + @TestMetadata("noRetention.kt") + public void testNoRetention() throws Exception { + runTest("idea/testData/quickfix/restrictedRetentionForExpressionAnnotation/addSourceRetention/noRetention.kt"); + } + + @TestMetadata("noRetention2.kt") + public void testNoRetention2() throws Exception { + runTest("idea/testData/quickfix/restrictedRetentionForExpressionAnnotation/addSourceRetention/noRetention2.kt"); + } + } + + @TestMetadata("idea/testData/quickfix/restrictedRetentionForExpressionAnnotation/changeRetentionToSource") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class ChangeRetentionToSource extends AbstractQuickFixTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, TargetBackend.ANY, testDataFilePath); + } + + public void testAllFilesPresentInChangeRetentionToSource() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/quickfix/restrictedRetentionForExpressionAnnotation/changeRetentionToSource"), Pattern.compile("^([\\w\\-_]+)\\.kt$"), TargetBackend.ANY, true); + } + + @TestMetadata("binaryRetention.kt") + public void testBinaryRetention() throws Exception { + runTest("idea/testData/quickfix/restrictedRetentionForExpressionAnnotation/changeRetentionToSource/binaryRetention.kt"); + } + + @TestMetadata("emptyRetention.kt") + public void testEmptyRetention() throws Exception { + runTest("idea/testData/quickfix/restrictedRetentionForExpressionAnnotation/changeRetentionToSource/emptyRetention.kt"); + } + + @TestMetadata("emptyRetention2.kt") + public void testEmptyRetention2() throws Exception { + runTest("idea/testData/quickfix/restrictedRetentionForExpressionAnnotation/changeRetentionToSource/emptyRetention2.kt"); + } + + @TestMetadata("emptyRetention3.kt") + public void testEmptyRetention3() throws Exception { + runTest("idea/testData/quickfix/restrictedRetentionForExpressionAnnotation/changeRetentionToSource/emptyRetention3.kt"); + } + + @TestMetadata("noRetention.kt") + public void testNoRetention() throws Exception { + runTest("idea/testData/quickfix/restrictedRetentionForExpressionAnnotation/changeRetentionToSource/noRetention.kt"); + } + } + + @TestMetadata("idea/testData/quickfix/restrictedRetentionForExpressionAnnotation/removeExpressionTarget") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class RemoveExpressionTarget extends AbstractQuickFixTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, TargetBackend.ANY, testDataFilePath); + } + + public void testAllFilesPresentInRemoveExpressionTarget() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/quickfix/restrictedRetentionForExpressionAnnotation/removeExpressionTarget"), Pattern.compile("^([\\w\\-_]+)\\.kt$"), TargetBackend.ANY, true); + } + + @TestMetadata("binaryRetention.kt") + public void testBinaryRetention() throws Exception { + runTest("idea/testData/quickfix/restrictedRetentionForExpressionAnnotation/removeExpressionTarget/binaryRetention.kt"); + } + + @TestMetadata("emptyRetention.kt") + public void testEmptyRetention() throws Exception { + runTest("idea/testData/quickfix/restrictedRetentionForExpressionAnnotation/removeExpressionTarget/emptyRetention.kt"); + } + + @TestMetadata("emptyRetention2.kt") + public void testEmptyRetention2() throws Exception { + runTest("idea/testData/quickfix/restrictedRetentionForExpressionAnnotation/removeExpressionTarget/emptyRetention2.kt"); + } + + @TestMetadata("noRetention.kt") + public void testNoRetention() throws Exception { + runTest("idea/testData/quickfix/restrictedRetentionForExpressionAnnotation/removeExpressionTarget/noRetention.kt"); + } + } + } + @TestMetadata("idea/testData/quickfix/simplifyComparison") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class)