Smaller range for SimplifyNegatedBinaryExpressionIntention
This commit is contained in:
+7
-2
@@ -17,12 +17,13 @@
|
|||||||
package org.jetbrains.kotlin.idea.intentions
|
package org.jetbrains.kotlin.idea.intentions
|
||||||
|
|
||||||
import com.intellij.openapi.editor.Editor
|
import com.intellij.openapi.editor.Editor
|
||||||
|
import com.intellij.openapi.util.TextRange
|
||||||
import com.intellij.psi.tree.IElementType
|
import com.intellij.psi.tree.IElementType
|
||||||
import org.jetbrains.kotlin.lexer.JetSingleValueToken
|
import org.jetbrains.kotlin.lexer.JetSingleValueToken
|
||||||
import org.jetbrains.kotlin.lexer.JetTokens
|
import org.jetbrains.kotlin.lexer.JetTokens
|
||||||
import org.jetbrains.kotlin.psi.*
|
import org.jetbrains.kotlin.psi.*
|
||||||
|
|
||||||
public class SimplifyNegatedBinaryExpressionIntention : JetSelfTargetingOffsetIndependentIntention<JetPrefixExpression>(javaClass(), "Simplify negated binary expression") {
|
public class SimplifyNegatedBinaryExpressionIntention : JetSelfTargetingRangeIntention<JetPrefixExpression>(javaClass(), "Simplify negated binary expression") {
|
||||||
|
|
||||||
private fun IElementType.negate(): JetSingleValueToken? = when (this) {
|
private fun IElementType.negate(): JetSingleValueToken? = when (this) {
|
||||||
JetTokens.IN_KEYWORD -> JetTokens.NOT_IN
|
JetTokens.IN_KEYWORD -> JetTokens.NOT_IN
|
||||||
@@ -43,7 +44,11 @@ public class SimplifyNegatedBinaryExpressionIntention : JetSelfTargetingOffsetIn
|
|||||||
else -> null
|
else -> null
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun isApplicableTo(element: JetPrefixExpression): Boolean {
|
override fun applicabilityRange(element: JetPrefixExpression): TextRange? {
|
||||||
|
return if (isApplicableTo(element)) element.getOperationReference().getTextRange() else null
|
||||||
|
}
|
||||||
|
|
||||||
|
public fun isApplicableTo(element: JetPrefixExpression): Boolean {
|
||||||
if (element.getOperationToken() != JetTokens.EXCL) return false
|
if (element.getOperationToken() != JetTokens.EXCL) return false
|
||||||
|
|
||||||
val expression = JetPsiUtil.deparenthesize(element.getBaseExpression()) as? JetOperationExpression ?: return false
|
val expression = JetPsiUtil.deparenthesize(element.getBaseExpression()) as? JetOperationExpression ?: return false
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// INTENTION_TEXT: Simplify negated '==' expression to '!='
|
// INTENTION_TEXT: Simplify negated '==' expression to '!='
|
||||||
fun test(n: Int) {
|
fun test(n: Int) {
|
||||||
!(0<caret> == 1)
|
!<caret>(0 == 1)
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
// INTENTION_TEXT: Simplify negated '>' expression to '<='
|
// INTENTION_TEXT: Simplify negated '>' expression to '<='
|
||||||
fun test(n: Int) {
|
fun test(n: Int) {
|
||||||
!(0<caret> > 1)
|
!<caret>(0 > 1)
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
// INTENTION_TEXT: Simplify negated '>=' expression to '<'
|
// INTENTION_TEXT: Simplify negated '>=' expression to '<'
|
||||||
fun test(n: Int) {
|
fun test(n: Int) {
|
||||||
!(0<caret> >= 1)
|
<caret>!(0 >= 1)
|
||||||
}
|
}
|
||||||
@@ -5,5 +5,5 @@ class A(val e: Int) {
|
|||||||
|
|
||||||
fun test(n: Int) {
|
fun test(n: Int) {
|
||||||
val a = A(1)
|
val a = A(1)
|
||||||
!(0<caret> in a)
|
<caret>!(0 in a)
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
// IS_APPLICABLE: false
|
// IS_APPLICABLE: false
|
||||||
fun Int.lt(b: Int): Boolean = this < b
|
fun Int.lt(b: Int): Boolean = this < b
|
||||||
fun test(n: Int) {
|
fun test(n: Int) {
|
||||||
!(1<caret> lt 2)
|
<caret>!(1 lt 2)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// INTENTION_TEXT: Simplify negated 'is' expression to '!is'
|
// INTENTION_TEXT: Simplify negated 'is' expression to '!is'
|
||||||
fun test(n: Int) {
|
fun test(n: Int) {
|
||||||
!(0<caret> is Int)
|
<caret>!(0 is Int)
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
// INTENTION_TEXT: Simplify negated '<' expression to '>='
|
// INTENTION_TEXT: Simplify negated '<' expression to '>='
|
||||||
fun test(n: Int) {
|
fun test(n: Int) {
|
||||||
!(0<caret> < 1)
|
<caret>!(0 < 1)
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
// INTENTION_TEXT: Simplify negated '<=' expression to '>'
|
// INTENTION_TEXT: Simplify negated '<=' expression to '>'
|
||||||
fun test(n: Int) {
|
fun test(n: Int) {
|
||||||
!(0<caret> <= 1)
|
<caret>!(0 <= 1)
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
// INTENTION_TEXT: Simplify negated '!=' expression to '=='
|
// INTENTION_TEXT: Simplify negated '!=' expression to '=='
|
||||||
fun test(n: Int) {
|
fun test(n: Int) {
|
||||||
!(0<caret> != 1)
|
<caret>!(0 != 1)
|
||||||
}
|
}
|
||||||
@@ -5,5 +5,5 @@ class A(val e: Int) {
|
|||||||
|
|
||||||
fun test(n: Int) {
|
fun test(n: Int) {
|
||||||
val a = A(1)
|
val a = A(1)
|
||||||
!(0<caret> !in a)
|
<caret>!(0 !in a)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// INTENTION_TEXT: Simplify negated '!is' expression to 'is'
|
// INTENTION_TEXT: Simplify negated '!is' expression to 'is'
|
||||||
fun test(n: Int) {
|
fun test(n: Int) {
|
||||||
!(0<caret> !is Int)
|
<caret>!(0 !is Int)
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user