From 269074b3991e67be8eb04050ae5aa2c4f1003ea4 Mon Sep 17 00:00:00 2001 From: Valentin Kipyatkov Date: Mon, 11 May 2015 18:04:04 +0300 Subject: [PATCH] Smaller range fro SafeAccessToIfThenIntention --- .../intentions/SafeAccessToIfThenIntention.kt | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/SafeAccessToIfThenIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/SafeAccessToIfThenIntention.kt index 72617a4882e..f31158fa659 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/SafeAccessToIfThenIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/SafeAccessToIfThenIntention.kt @@ -17,16 +17,20 @@ package org.jetbrains.kotlin.idea.intentions.branchedTransformations.intentions import com.intellij.openapi.editor.Editor +import com.intellij.openapi.util.TextRange import org.jetbrains.kotlin.idea.caches.resolve.analyze -import org.jetbrains.kotlin.idea.intentions.JetSelfTargetingOffsetIndependentIntention +import org.jetbrains.kotlin.idea.intentions.JetSelfTargetingRangeIntention import org.jetbrains.kotlin.idea.intentions.branchedTransformations.convertToIfNotNullExpression import org.jetbrains.kotlin.idea.intentions.branchedTransformations.introduceValueForCondition import org.jetbrains.kotlin.idea.intentions.branchedTransformations.isStableVariable import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.resolve.bindingContextUtil.isUsedAsStatement -public class SafeAccessToIfThenIntention : JetSelfTargetingOffsetIndependentIntention(javaClass(), "Replace safe access expression with 'if' expression") { - override fun isApplicableTo(element: JetSafeQualifiedExpression): Boolean = element.getSelectorExpression() != null +public class SafeAccessToIfThenIntention : JetSelfTargetingRangeIntention(javaClass(), "Replace safe access expression with 'if' expression") { + override fun applicabilityRange(element: JetSafeQualifiedExpression): TextRange? { + if (element.getSelectorExpression() == null) return null + return element.getOperationTokenNode().getTextRange() + } override fun applyTo(element: JetSafeQualifiedExpression, editor: Editor) { val receiver = JetPsiUtil.safeDeparenthesize(element.getReceiverExpression())