ReplaceWithTraditionalAssignmentIntention - smaller range

This commit is contained in:
Valentin Kipyatkov
2015-04-29 19:36:40 +03:00
parent 8fc799322b
commit c617d5256e
6 changed files with 11 additions and 10 deletions
@@ -22,11 +22,12 @@ import org.jetbrains.kotlin.psi.JetBinaryExpression
import org.jetbrains.kotlin.psi.JetPsiFactory import org.jetbrains.kotlin.psi.JetPsiFactory
import org.jetbrains.kotlin.psi.JetSimpleNameExpression import org.jetbrains.kotlin.psi.JetSimpleNameExpression
public class ReplaceWithTraditionalAssignmentIntention : JetSelfTargetingOffsetIndependentIntention<JetBinaryExpression>(javaClass(), "Replace with traditional assignment") { public class ReplaceWithTraditionalAssignmentIntention : JetSelfTargetingIntention<JetBinaryExpression>(javaClass(), "Replace with traditional assignment") {
override fun isApplicableTo(element: JetBinaryExpression): Boolean { override fun isApplicableTo(element: JetBinaryExpression, caretOffset: Int): Boolean {
return element.getOperationToken() in JetTokens.AUGMENTED_ASSIGNMENTS if (element.getOperationToken() !in JetTokens.AUGMENTED_ASSIGNMENTS) return false
&& element.getLeft() is JetSimpleNameExpression if (element.getLeft() !is JetSimpleNameExpression) return false
&& element.getRight() != null if (element.getRight() == null) return false
return element.getOperationReference().getTextRange().containsOffset(caretOffset)
} }
override fun applyTo(element: JetBinaryExpression, editor: Editor) { override fun applyTo(element: JetBinaryExpression, editor: Editor) {
@@ -2,5 +2,5 @@ fun foo() {
var x = 0 var x = 0
val a = 1 val a = 1
val b = 1 val b = 1
<caret>x += a / b x <caret>+= a / b
} }
@@ -1,5 +1,5 @@
// IS_APPLICABLE: false // IS_APPLICABLE: false
fun foo() { fun foo() {
var x = 0 var x = 0
<caret>x + 1 x <caret>+ 1
} }
@@ -3,5 +3,5 @@ fun foo() {
var x = 0 var x = 0
val a = 1 val a = 1
val b = 1 val b = 1
<caret>x = a / b x <caret>= a / b
} }
@@ -1,4 +1,4 @@
fun foo() { fun foo() {
var x = 0 var x = 0
<caret>x += 1 x <caret>+= 1
} }
@@ -1,4 +1,4 @@
fun foo() { fun foo() {
var x = 0 var x = 0
<caret>x = x + 1 x <caret>= x + 1
} }