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:
Denis Zharkov
2016-10-04 18:04:20 +03:00
parent 7353b08f09
commit 4910024cdb
16 changed files with 17 additions and 22 deletions
@@ -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
}
+1 -1
View File
@@ -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
}
+1 -1
View File
@@ -2,5 +2,5 @@
fun foo() {
@Suppress("UNNECESSARY_NOT_NULL_ASSERTION")
(1<caret>!! == 2)
1<caret>!! == 2
}
+1 -1
View File
@@ -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
}
+1 -1
View File
@@ -2,5 +2,5 @@
fun foo() {
@Suppress("UNNECESSARY_NOT_NULL_ASSERTION")
(""<caret>!! is String)
""<caret>!! is String
}
+1 -1
View File
@@ -2,5 +2,5 @@
fun foo() {
@Suppress("UNNECESSARY_NOT_NULL_ASSERTION")
(1<caret>!! < 2)
1<caret>!! < 2
}
+1 -1
View File
@@ -2,5 +2,5 @@
fun foo() {
@Suppress("UNNECESSARY_NOT_NULL_ASSERTION")
(1<caret>!! * 2)
1<caret>!! * 2
}
+1 -1
View File
@@ -2,5 +2,5 @@
fun foo() {
@Suppress("UNNECESSARY_NOT_NULL_ASSERTION")
(false<caret>!! || true)
false<caret>!! || true
}
+1 -1
View File
@@ -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
}