From ecda8cd889a5e30d0ea3745bd83a80fd4bcaa1ea Mon Sep 17 00:00:00 2001 From: Nikolay Krasko Date: Fri, 5 Apr 2019 14:55:35 +0300 Subject: [PATCH] Remove resolve in ChangeRetentionToSourceFix and RemoveExpressionTargetFix (KT-25574) --- ...RetentionForExpressionAnnotationFactory.kt | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/RestrictedRetentionForExpressionAnnotationFactory.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/RestrictedRetentionForExpressionAnnotationFactory.kt index 288b5cce8fd..429799cfea5 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/RestrictedRetentionForExpressionAnnotationFactory.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/RestrictedRetentionForExpressionAnnotationFactory.kt @@ -27,9 +27,11 @@ object RestrictedRetentionForExpressionAnnotationFactory : KotlinIntentionAction 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) + val targetAnnotation = containingClass.annotation(KotlinBuiltIns.FQ_NAMES.target) + + return listOfNotNull( + if (targetAnnotation != null) RemoveExpressionTargetFix(targetAnnotation) else null, + if (retentionAnnotation == null) AddSourceRetentionFix(containingClass) else ChangeRetentionToSourceFix(retentionAnnotation) ) } @@ -52,13 +54,15 @@ object RestrictedRetentionForExpressionAnnotationFactory : KotlinIntentionAction } } - private class ChangeRetentionToSourceFix(element: KtClass) : KotlinQuickFixAction(element) { + private class ChangeRetentionToSourceFix(retentionAnnotation: KtAnnotationEntry) : + KotlinQuickFixAction(retentionAnnotation) { + 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 retentionAnnotation = element ?: return val psiFactory = KtPsiFactory(retentionAnnotation) val added = if (retentionAnnotation.valueArgumentList == null) { retentionAnnotation.add(psiFactory.createCallArguments("($sourceRetention)")) as KtValueArgumentList @@ -74,13 +78,16 @@ object RestrictedRetentionForExpressionAnnotationFactory : KotlinIntentionAction } } - private class RemoveExpressionTargetFix(element: KtClass) : KotlinQuickFixAction(element) { + private class RemoveExpressionTargetFix(targetAnnotation: KtAnnotationEntry) : + KotlinQuickFixAction(targetAnnotation) { + 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() + val targetAnnotation = element ?: return + targetAnnotation.delete() } } } \ No newline at end of file