diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/RemoveAtFromAnnotationArgument.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/RemoveAtFromAnnotationArgument.kt index b4ed379ada1..435f31b23d2 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/RemoveAtFromAnnotationArgument.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/RemoveAtFromAnnotationArgument.kt @@ -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? = - (diagnostic.psiElement as? KtAnnotationEntry)?.let { RemoveAtFromAnnotationArgument(it) } + (diagnostic.psiElement as? KtAnnotationEntry)?.let { RemoveAtFromAnnotationArgument(it) } } } diff --git a/idea/testData/quickfix/removeAtFromAnnotationArgument/namedParam.kt b/idea/testData/quickfix/removeAtFromAnnotationArgument/namedParam.kt index 1cc36a7920e..f8badd71e9a 100644 --- a/idea/testData/quickfix/removeAtFromAnnotationArgument/namedParam.kt +++ b/idea/testData/quickfix/removeAtFromAnnotationArgument/namedParam.kt @@ -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) diff --git a/idea/testData/quickfix/removeAtFromAnnotationArgument/namedParam.kt.after b/idea/testData/quickfix/removeAtFromAnnotationArgument/namedParam.kt.after index 3fc593c6305..bdeededcc0e 100644 --- a/idea/testData/quickfix/removeAtFromAnnotationArgument/namedParam.kt.after +++ b/idea/testData/quickfix/removeAtFromAnnotationArgument/namedParam.kt.after @@ -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) diff --git a/idea/testData/quickfix/removeAtFromAnnotationArgument/simple.kt b/idea/testData/quickfix/removeAtFromAnnotationArgument/simple.kt index 2b7d0c165b2..c11d0a133e2 100644 --- a/idea/testData/quickfix/removeAtFromAnnotationArgument/simple.kt +++ b/idea/testData/quickfix/removeAtFromAnnotationArgument/simple.kt @@ -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) diff --git a/idea/testData/quickfix/removeAtFromAnnotationArgument/simple.kt.after b/idea/testData/quickfix/removeAtFromAnnotationArgument/simple.kt.after index 43a4a423d99..73d3b32bb99 100644 --- a/idea/testData/quickfix/removeAtFromAnnotationArgument/simple.kt.after +++ b/idea/testData/quickfix/removeAtFromAnnotationArgument/simple.kt.after @@ -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)