Change deprecation rules for annotations in brackets
Also adjust quickfix for deprecated syntax
This commit is contained in:
@@ -22,10 +22,12 @@ import com.intellij.openapi.project.Project
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.PsiWhiteSpace
|
||||
import org.jetbrains.kotlin.diagnostics.Diagnostic
|
||||
import org.jetbrains.kotlin.idea.quickfix.quickfixUtil.addConstructorKeyword
|
||||
import org.jetbrains.kotlin.idea.quickfix.quickfixUtil.createIntentionFactory
|
||||
import org.jetbrains.kotlin.idea.quickfix.quickfixUtil.createIntentionForFirstParentOfType
|
||||
import org.jetbrains.kotlin.psi.JetAnnotation
|
||||
import org.jetbrains.kotlin.psi.JetFile
|
||||
import org.jetbrains.kotlin.psi.JetPrimaryConstructor
|
||||
import org.jetbrains.kotlin.psi.JetPsiFactory
|
||||
|
||||
public class DeprecatedAnnotationSyntaxFix(element: JetAnnotation) : JetIntentionAction<JetAnnotation>(element) {
|
||||
@@ -51,11 +53,15 @@ public class DeprecatedAnnotationSyntaxFix(element: JetAnnotation) : JetIntentio
|
||||
private fun replaceWithAtAnnotationEntries(annotation: JetAnnotation) {
|
||||
val psiFactory = JetPsiFactory(annotation)
|
||||
|
||||
val hasFileKeyword = annotation.hasFileKeyword()
|
||||
|
||||
val parent = annotation.getParent()
|
||||
val owner = parent.getParent()
|
||||
var prevElement: PsiElement = annotation
|
||||
|
||||
for (entry in annotation.getEntries()) {
|
||||
val newEntry = psiFactory.createAnnotationEntry("@" + entry.getText())
|
||||
val newEntry = if (hasFileKeyword) createFileAnnotationEntry(psiFactory, entry.getText())
|
||||
else psiFactory.createAnnotationEntry("@" + entry.getText())
|
||||
val added = parent.addAfter(newEntry, prevElement)
|
||||
|
||||
if (prevElement != annotation) {
|
||||
@@ -65,7 +71,14 @@ public class DeprecatedAnnotationSyntaxFix(element: JetAnnotation) : JetIntentio
|
||||
prevElement = added
|
||||
}
|
||||
|
||||
if (owner is JetPrimaryConstructor) {
|
||||
owner.addConstructorKeyword()
|
||||
}
|
||||
|
||||
annotation.delete()
|
||||
}
|
||||
|
||||
private fun createFileAnnotationEntry(psiFactory: JetPsiFactory, text: String) =
|
||||
psiFactory.createFile("@file:$text").getAnnotationEntries().first()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
[file: kotlin.deprecated("message")]
|
||||
[file: suppress(<error>BAR</error>)]
|
||||
[file: suppress(BAZ)]
|
||||
@file:kotlin.deprecated("message")
|
||||
@file:suppress(<error>BAR</error>)
|
||||
@file:suppress(BAZ)
|
||||
|
||||
[<error>k</error>otlin.deprecated("message")]
|
||||
[<error>s</error>uppress(<error>BAR</error>)]
|
||||
[<error>s</error>uppress(BAZ)]
|
||||
@<error>k</error>otlin.deprecated("message")
|
||||
@<error>s</error>uppress(<error>BAR</error>)
|
||||
@<error>s</error>uppress(BAZ)
|
||||
|
||||
[file: myAnnotation(1, "string")]
|
||||
[file: boo.myAnnotation(1, <error>BAR</error>)]
|
||||
[file: myAnnotation(N, BAZ)]
|
||||
@file:myAnnotation(1, "string")
|
||||
@file:boo.myAnnotation(1, <error>BAR</error>)
|
||||
@file:myAnnotation(N, BAZ)
|
||||
|
||||
[<error>m</error>yAnnotation(1, "string")]
|
||||
[<error>b</error>oo.myAnnotation(1, "string")]
|
||||
[<error>m</error>yAnnotation(N, BAZ)]
|
||||
@<error>m</error>yAnnotation(1, "string")
|
||||
@<error>b</error>oo.myAnnotation(1, "string")
|
||||
@<error>m</error>yAnnotation(N, BAZ)
|
||||
|
||||
package boo
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ fun testVisibility() {
|
||||
<error descr="[UNRESOLVED_REFERENCE] Unresolved reference: ClassInM2">ClassInM2</error>()
|
||||
}
|
||||
|
||||
public open class A internal () {
|
||||
public open class A internal constructor() {
|
||||
private fun pri() {
|
||||
}
|
||||
fun int() {
|
||||
|
||||
+2
-2
@@ -1,3 +1,3 @@
|
||||
[file: Ann]
|
||||
@file:Ann
|
||||
|
||||
@Ann class B [Ann(1)]()
|
||||
@Ann class B @Ann(1) constructor()
|
||||
|
||||
Reference in New Issue
Block a user