Smaller range for SimplifyNegatedBinaryExpressionIntention

This commit is contained in:
Valentin Kipyatkov
2015-05-12 15:02:02 +03:00
parent fc3609d403
commit 9a97818b82
12 changed files with 18 additions and 13 deletions
@@ -17,12 +17,13 @@
package org.jetbrains.kotlin.idea.intentions
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.util.TextRange
import com.intellij.psi.tree.IElementType
import org.jetbrains.kotlin.lexer.JetSingleValueToken
import org.jetbrains.kotlin.lexer.JetTokens
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) {
JetTokens.IN_KEYWORD -> JetTokens.NOT_IN
@@ -43,7 +44,11 @@ public class SimplifyNegatedBinaryExpressionIntention : JetSelfTargetingOffsetIn
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
val expression = JetPsiUtil.deparenthesize(element.getBaseExpression()) as? JetOperationExpression ?: return false
@@ -1,4 +1,4 @@
// INTENTION_TEXT: Simplify negated '==' expression to '!='
fun test(n: Int) {
!(0<caret> == 1)
!<caret>(0 == 1)
}
@@ -1,4 +1,4 @@
// INTENTION_TEXT: Simplify negated '>' expression to '<='
fun test(n: Int) {
!(0<caret> > 1)
!<caret>(0 > 1)
}
@@ -1,4 +1,4 @@
// INTENTION_TEXT: Simplify negated '>=' expression to '<'
fun test(n: Int) {
!(0<caret> >= 1)
<caret>!(0 >= 1)
}
@@ -5,5 +5,5 @@ class A(val e: Int) {
fun test(n: Int) {
val a = A(1)
!(0<caret> in a)
<caret>!(0 in a)
}
@@ -1,5 +1,5 @@
// IS_APPLICABLE: false
fun Int.lt(b: Int): Boolean = this < b
fun test(n: Int) {
!(1<caret> lt 2)
<caret>!(1 lt 2)
}
@@ -1,4 +1,4 @@
// INTENTION_TEXT: Simplify negated 'is' expression to '!is'
fun test(n: Int) {
!(0<caret> is Int)
<caret>!(0 is Int)
}
@@ -1,4 +1,4 @@
// INTENTION_TEXT: Simplify negated '<' expression to '>='
fun test(n: Int) {
!(0<caret> < 1)
<caret>!(0 < 1)
}
@@ -1,4 +1,4 @@
// INTENTION_TEXT: Simplify negated '<=' expression to '>'
fun test(n: Int) {
!(0<caret> <= 1)
<caret>!(0 <= 1)
}
@@ -1,4 +1,4 @@
// INTENTION_TEXT: Simplify negated '!=' expression to '=='
fun test(n: Int) {
!(0<caret> != 1)
<caret>!(0 != 1)
}
@@ -5,5 +5,5 @@ class A(val e: Int) {
fun test(n: Int) {
val a = A(1)
!(0<caret> !in a)
<caret>!(0 !in a)
}
@@ -1,4 +1,4 @@
// INTENTION_TEXT: Simplify negated '!is' expression to 'is'
fun test(n: Int) {
!(0<caret> !is Int)
<caret>!(0 !is Int)
}