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.JetSimpleNameExpression
public class ReplaceWithTraditionalAssignmentIntention : JetSelfTargetingOffsetIndependentIntention<JetBinaryExpression>(javaClass(), "Replace with traditional assignment") {
override fun isApplicableTo(element: JetBinaryExpression): Boolean {
return element.getOperationToken() in JetTokens.AUGMENTED_ASSIGNMENTS
&& element.getLeft() is JetSimpleNameExpression
&& element.getRight() != null
public class ReplaceWithTraditionalAssignmentIntention : JetSelfTargetingIntention<JetBinaryExpression>(javaClass(), "Replace with traditional assignment") {
override fun isApplicableTo(element: JetBinaryExpression, caretOffset: Int): Boolean {
if (element.getOperationToken() !in JetTokens.AUGMENTED_ASSIGNMENTS) return false
if (element.getLeft() !is JetSimpleNameExpression) return false
if (element.getRight() == null) return false
return element.getOperationReference().getTextRange().containsOffset(caretOffset)
}
override fun applyTo(element: JetBinaryExpression, editor: Editor) {
@@ -2,5 +2,5 @@ fun foo() {
var x = 0
val a = 1
val b = 1
<caret>x += a / b
x <caret>+= a / b
}
@@ -1,5 +1,5 @@
// IS_APPLICABLE: false
fun foo() {
var x = 0
<caret>x + 1
x <caret>+ 1
}
@@ -3,5 +3,5 @@ fun foo() {
var x = 0
val a = 1
val b = 1
<caret>x = a / b
x <caret>= a / b
}
@@ -1,4 +1,4 @@
fun foo() {
var x = 0
<caret>x += 1
x <caret>+= 1
}
@@ -1,4 +1,4 @@
fun foo() {
var x = 0
<caret>x = x + 1
x <caret>= x + 1
}