Remove resolve in ChangeRetentionToSourceFix and RemoveExpressionTargetFix (KT-25574)
This commit is contained in:
+14
-7
@@ -27,9 +27,11 @@ object RestrictedRetentionForExpressionAnnotationFactory : KotlinIntentionAction
|
|||||||
val annotationEntry = diagnostic.psiElement as? KtAnnotationEntry ?: return emptyList()
|
val annotationEntry = diagnostic.psiElement as? KtAnnotationEntry ?: return emptyList()
|
||||||
val containingClass = annotationEntry.containingClass() ?: return emptyList()
|
val containingClass = annotationEntry.containingClass() ?: return emptyList()
|
||||||
val retentionAnnotation = containingClass.annotation(KotlinBuiltIns.FQ_NAMES.retention)
|
val retentionAnnotation = containingClass.annotation(KotlinBuiltIns.FQ_NAMES.retention)
|
||||||
return listOf(
|
val targetAnnotation = containingClass.annotation(KotlinBuiltIns.FQ_NAMES.target)
|
||||||
RemoveExpressionTargetFix(containingClass),
|
|
||||||
if (retentionAnnotation == null) AddSourceRetentionFix(containingClass) else ChangeRetentionToSourceFix(containingClass)
|
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<KtClass>(element) {
|
private class ChangeRetentionToSourceFix(retentionAnnotation: KtAnnotationEntry) :
|
||||||
|
KotlinQuickFixAction<KtAnnotationEntry>(retentionAnnotation) {
|
||||||
|
|
||||||
override fun getText() = "Change existent retention to SOURCE"
|
override fun getText() = "Change existent retention to SOURCE"
|
||||||
|
|
||||||
override fun getFamilyName() = text
|
override fun getFamilyName() = text
|
||||||
|
|
||||||
override fun invoke(project: Project, editor: Editor?, file: KtFile) {
|
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 psiFactory = KtPsiFactory(retentionAnnotation)
|
||||||
val added = if (retentionAnnotation.valueArgumentList == null) {
|
val added = if (retentionAnnotation.valueArgumentList == null) {
|
||||||
retentionAnnotation.add(psiFactory.createCallArguments("($sourceRetention)")) as KtValueArgumentList
|
retentionAnnotation.add(psiFactory.createCallArguments("($sourceRetention)")) as KtValueArgumentList
|
||||||
@@ -74,13 +78,16 @@ object RestrictedRetentionForExpressionAnnotationFactory : KotlinIntentionAction
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class RemoveExpressionTargetFix(element: KtClass) : KotlinQuickFixAction<KtClass>(element) {
|
private class RemoveExpressionTargetFix(targetAnnotation: KtAnnotationEntry) :
|
||||||
|
KotlinQuickFixAction<KtAnnotationEntry>(targetAnnotation) {
|
||||||
|
|
||||||
override fun getText() = "Remove EXPRESSION target"
|
override fun getText() = "Remove EXPRESSION target"
|
||||||
|
|
||||||
override fun getFamilyName() = text
|
override fun getFamilyName() = text
|
||||||
|
|
||||||
override fun invoke(project: Project, editor: Editor?, file: KtFile) {
|
override fun invoke(project: Project, editor: Editor?, file: KtFile) {
|
||||||
element?.annotation(KotlinBuiltIns.FQ_NAMES.target)?.delete()
|
val targetAnnotation = element ?: return
|
||||||
|
targetAnnotation.delete()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user