Smaller range fro SafeAccessToIfThenIntention

This commit is contained in:
Valentin Kipyatkov
2015-05-11 18:04:04 +03:00
parent 776e653421
commit 269074b399
@@ -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<JetSafeQualifiedExpression>(javaClass(), "Replace safe access expression with 'if' expression") {
override fun isApplicableTo(element: JetSafeQualifiedExpression): Boolean = element.getSelectorExpression() != null
public class SafeAccessToIfThenIntention : JetSelfTargetingRangeIntention<JetSafeQualifiedExpression>(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())