Fix "Remove @ from annotation argument" (make consistent PSI)

Three relevant quick-fix tests should be fixed after it
This commit is contained in:
Mikhail Glukhikh
2018-08-06 17:15:37 +03:00
parent 9ad2edbe85
commit 28484f31e7
5 changed files with 5 additions and 8 deletions
@@ -19,6 +19,7 @@ package org.jetbrains.kotlin.idea.quickfix
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.project.Project
import org.jetbrains.kotlin.diagnostics.Diagnostic
import org.jetbrains.kotlin.psi.KtAnnotatedExpression
import org.jetbrains.kotlin.psi.KtAnnotationEntry
import org.jetbrains.kotlin.psi.KtFile
import org.jetbrains.kotlin.psi.KtPsiFactory
@@ -30,15 +31,15 @@ class RemoveAtFromAnnotationArgument(constructor: KtAnnotationEntry) : KotlinQui
override fun getFamilyName() = text
override fun invoke(project: Project, editor: Editor?, file: KtFile) {
val element = element ?: return
val elementToReplace = (element?.parent as? KtAnnotatedExpression) ?: return
val noAt = KtPsiFactory(element.project).createExpression(element.text.replaceFirst("@", ""))
element.replace(noAt)
val noAt = KtPsiFactory(elementToReplace.project).createExpression(elementToReplace.text.replaceFirst("@", ""))
elementToReplace.replace(noAt)
}
companion object : KotlinSingleIntentionActionFactory() {
override fun createAction(diagnostic: Diagnostic): KotlinQuickFixAction<KtAnnotationEntry>? =
(diagnostic.psiElement as? KtAnnotationEntry)?.let { RemoveAtFromAnnotationArgument(it) }
(diagnostic.psiElement as? KtAnnotationEntry)?.let { RemoveAtFromAnnotationArgument(it) }
}
}
@@ -1,5 +1,4 @@
// "Remove @ from annotation argument" "true"
// ERROR: An annotation argument must be a compile-time constant
annotation class Y()
annotation class X(val value: Y, val y: Y)
@@ -1,5 +1,4 @@
// "Remove @ from annotation argument" "true"
// ERROR: An annotation argument must be a compile-time constant
annotation class Y()
annotation class X(val value: Y, val y: Y)
@@ -1,5 +1,4 @@
// "Remove @ from annotation argument" "true"
// ERROR: An annotation argument must be a compile-time constant
annotation class Y()
annotation class X(val value: Y)
@@ -1,5 +1,4 @@
// "Remove @ from annotation argument" "true"
// ERROR: An annotation argument must be a compile-time constant
annotation class Y()
annotation class X(val value: Y)