Fix "Remove @ from annotation argument" (make consistent PSI)
Three relevant quick-fix tests should be fixed after it
This commit is contained in:
@@ -19,6 +19,7 @@ package org.jetbrains.kotlin.idea.quickfix
|
|||||||
import com.intellij.openapi.editor.Editor
|
import com.intellij.openapi.editor.Editor
|
||||||
import com.intellij.openapi.project.Project
|
import com.intellij.openapi.project.Project
|
||||||
import org.jetbrains.kotlin.diagnostics.Diagnostic
|
import org.jetbrains.kotlin.diagnostics.Diagnostic
|
||||||
|
import org.jetbrains.kotlin.psi.KtAnnotatedExpression
|
||||||
import org.jetbrains.kotlin.psi.KtAnnotationEntry
|
import org.jetbrains.kotlin.psi.KtAnnotationEntry
|
||||||
import org.jetbrains.kotlin.psi.KtFile
|
import org.jetbrains.kotlin.psi.KtFile
|
||||||
import org.jetbrains.kotlin.psi.KtPsiFactory
|
import org.jetbrains.kotlin.psi.KtPsiFactory
|
||||||
@@ -30,15 +31,15 @@ class RemoveAtFromAnnotationArgument(constructor: KtAnnotationEntry) : KotlinQui
|
|||||||
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 element = element ?: return
|
val elementToReplace = (element?.parent as? KtAnnotatedExpression) ?: return
|
||||||
|
|
||||||
val noAt = KtPsiFactory(element.project).createExpression(element.text.replaceFirst("@", ""))
|
val noAt = KtPsiFactory(elementToReplace.project).createExpression(elementToReplace.text.replaceFirst("@", ""))
|
||||||
element.replace(noAt)
|
elementToReplace.replace(noAt)
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object : KotlinSingleIntentionActionFactory() {
|
companion object : KotlinSingleIntentionActionFactory() {
|
||||||
override fun createAction(diagnostic: Diagnostic): KotlinQuickFixAction<KtAnnotationEntry>? =
|
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"
|
// "Remove @ from annotation argument" "true"
|
||||||
// ERROR: An annotation argument must be a compile-time constant
|
|
||||||
|
|
||||||
annotation class Y()
|
annotation class Y()
|
||||||
annotation class X(val value: Y, val y: Y)
|
annotation class X(val value: Y, val y: Y)
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
// "Remove @ from annotation argument" "true"
|
// "Remove @ from annotation argument" "true"
|
||||||
// ERROR: An annotation argument must be a compile-time constant
|
|
||||||
|
|
||||||
annotation class Y()
|
annotation class Y()
|
||||||
annotation class X(val value: Y, val y: Y)
|
annotation class X(val value: Y, val y: Y)
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
// "Remove @ from annotation argument" "true"
|
// "Remove @ from annotation argument" "true"
|
||||||
// ERROR: An annotation argument must be a compile-time constant
|
|
||||||
|
|
||||||
annotation class Y()
|
annotation class Y()
|
||||||
annotation class X(val value: Y)
|
annotation class X(val value: Y)
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
// "Remove @ from annotation argument" "true"
|
// "Remove @ from annotation argument" "true"
|
||||||
// ERROR: An annotation argument must be a compile-time constant
|
|
||||||
|
|
||||||
annotation class Y()
|
annotation class Y()
|
||||||
annotation class X(val value: Y)
|
annotation class X(val value: Y)
|
||||||
|
|||||||
Reference in New Issue
Block a user