Fix suppress at statement intention for asigmnents
There's no need now to consider precedence of element as annotation preceding the beginning of block statement is always now attached to the whole statement #KT-11673 Fixed #KT-12780 Fixed
This commit is contained in:
+3
-6
@@ -23,7 +23,6 @@ import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.idea.KotlinBundle
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
||||
import org.jetbrains.kotlin.idea.util.PsiPrecedences
|
||||
import org.jetbrains.kotlin.idea.util.addAnnotation
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.replaceFileAnnotationList
|
||||
@@ -90,7 +89,7 @@ class KotlinSuppressIntentionAction private constructor(
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
addArgumentToSuppressAnnotation(suppressAnnotation, id)
|
||||
}
|
||||
|
||||
@@ -109,10 +108,8 @@ class KotlinSuppressIntentionAction private constructor(
|
||||
val suppressAt = caretBox.expression
|
||||
assert(suppressAt !is KtDeclaration) { "Declarations should have been checked for above" }
|
||||
|
||||
val parentheses = PsiPrecedences.getPrecedence(suppressAt) > PsiPrecedences.PRECEDENCE_OF_PREFIX_EXPRESSION
|
||||
val placeholderText = "PLACEHOLDER_ID"
|
||||
val inner = if (parentheses) "($placeholderText)" else placeholderText
|
||||
val annotatedExpression = KtPsiFactory(suppressAt).createExpression(suppressAnnotationText(id) + "\n" + inner)
|
||||
val annotatedExpression = KtPsiFactory(suppressAt).createExpression(suppressAnnotationText(id) + "\n" + placeholderText)
|
||||
|
||||
val copy = suppressAt.copy()!!
|
||||
|
||||
@@ -181,4 +178,4 @@ private class CaretBox<out E: KtExpression>(
|
||||
if (editor == null) return
|
||||
editor.caretModel.moveToOffset(copy.textOffset + offsetInExpression)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,5 +2,5 @@
|
||||
|
||||
fun foo() {
|
||||
@Suppress("UNNECESSARY_NOT_NULL_ASSERTION")
|
||||
(false<caret>!! && true)
|
||||
false<caret>!! && true
|
||||
}
|
||||
@@ -2,5 +2,5 @@
|
||||
|
||||
fun foo() {
|
||||
@Suppress("UNNECESSARY_NOT_NULL_ASSERTION")
|
||||
(""<caret>!! as String)
|
||||
""<caret>!! as String
|
||||
}
|
||||
@@ -2,5 +2,5 @@
|
||||
|
||||
fun foo() {
|
||||
@Suppress("UNNECESSARY_NOT_NULL_ASSERTION")
|
||||
(""<caret>!! as? String)
|
||||
""<caret>!! as? String
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
// "Suppress 'UNNECESSARY_NOT_NULL_ASSERTION' for statement " "true"
|
||||
// ERROR: Assignments are not expressions, and only expressions are allowed in this context
|
||||
|
||||
fun foo() {
|
||||
var x = 0
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
// "Suppress 'UNNECESSARY_NOT_NULL_ASSERTION' for statement " "true"
|
||||
// ERROR: Assignments are not expressions, and only expressions are allowed in this context
|
||||
|
||||
fun foo() {
|
||||
var x = 0
|
||||
@Suppress("UNNECESSARY_NOT_NULL_ASSERTION")
|
||||
(x = 1<caret>!!)
|
||||
x = 1<caret>!!
|
||||
}
|
||||
@@ -2,5 +2,5 @@
|
||||
|
||||
fun foo() {
|
||||
@Suppress("UNNECESSARY_NOT_NULL_ASSERTION")
|
||||
(1<caret>!! ?: 0)
|
||||
1<caret>!! ?: 0
|
||||
}
|
||||
@@ -2,5 +2,5 @@
|
||||
|
||||
fun foo() {
|
||||
@Suppress("UNNECESSARY_NOT_NULL_ASSERTION")
|
||||
(1<caret>!! == 2)
|
||||
1<caret>!! == 2
|
||||
}
|
||||
@@ -2,5 +2,5 @@
|
||||
|
||||
fun foo() {
|
||||
@Suppress("UNNECESSARY_NOT_NULL_ASSERTION")
|
||||
(1<caret>!! in (1..2))
|
||||
1<caret>!! in (1..2)
|
||||
}
|
||||
@@ -4,5 +4,5 @@ infix fun Int.add(other: Int) = this + other
|
||||
|
||||
fun foo() {
|
||||
@Suppress("UNNECESSARY_NOT_NULL_ASSERTION")
|
||||
(1!! add 2)
|
||||
1!! add 2
|
||||
}
|
||||
@@ -2,5 +2,5 @@
|
||||
|
||||
fun foo() {
|
||||
@Suppress("UNNECESSARY_NOT_NULL_ASSERTION")
|
||||
(""<caret>!! is String)
|
||||
""<caret>!! is String
|
||||
}
|
||||
@@ -2,5 +2,5 @@
|
||||
|
||||
fun foo() {
|
||||
@Suppress("UNNECESSARY_NOT_NULL_ASSERTION")
|
||||
(1<caret>!! < 2)
|
||||
1<caret>!! < 2
|
||||
}
|
||||
@@ -2,5 +2,5 @@
|
||||
|
||||
fun foo() {
|
||||
@Suppress("UNNECESSARY_NOT_NULL_ASSERTION")
|
||||
(1<caret>!! * 2)
|
||||
1<caret>!! * 2
|
||||
}
|
||||
@@ -2,5 +2,5 @@
|
||||
|
||||
fun foo() {
|
||||
@Suppress("UNNECESSARY_NOT_NULL_ASSERTION")
|
||||
(false<caret>!! || true)
|
||||
false<caret>!! || true
|
||||
}
|
||||
@@ -2,5 +2,5 @@
|
||||
|
||||
fun foo() {
|
||||
@Suppress("UNNECESSARY_NOT_NULL_ASSERTION")
|
||||
(1<caret>!! + 2)
|
||||
1<caret>!! + 2
|
||||
}
|
||||
@@ -2,5 +2,5 @@
|
||||
|
||||
fun foo() {
|
||||
@Suppress("UNNECESSARY_NOT_NULL_ASSERTION")
|
||||
(1<caret>!! .. 2)
|
||||
1<caret>!! .. 2
|
||||
}
|
||||
Reference in New Issue
Block a user