From b94d6306a72c9417ec47f25baaa0403ee35f0507 Mon Sep 17 00:00:00 2001 From: Valentin Kipyatkov Date: Mon, 11 May 2015 16:49:50 +0300 Subject: [PATCH] Minor --- .../intentions/DoubleBangToIfThenIntention.kt | 9 +++++---- .../intentions/IfToWhenIntention.kt | 11 ++++++----- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/DoubleBangToIfThenIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/DoubleBangToIfThenIntention.kt index 051ff9d64db..2388b8e708b 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/DoubleBangToIfThenIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/DoubleBangToIfThenIntention.kt @@ -21,9 +21,10 @@ import com.intellij.codeInsight.template.TemplateBuilderImpl import com.intellij.codeInsight.template.TemplateEditingAdapter import com.intellij.codeInsight.template.TemplateManager import com.intellij.openapi.editor.Editor +import com.intellij.openapi.util.TextRange import com.intellij.psi.PsiDocumentManager import org.apache.commons.lang.StringEscapeUtils.escapeJava -import org.jetbrains.kotlin.idea.intentions.JetSelfTargetingIntention +import org.jetbrains.kotlin.idea.intentions.JetSelfTargetingRangeIntention import org.jetbrains.kotlin.idea.intentions.JetTypeLookupExpression import org.jetbrains.kotlin.idea.intentions.branchedTransformations.* import org.jetbrains.kotlin.lexer.JetTokens @@ -32,9 +33,9 @@ import org.jetbrains.kotlin.psi.JetPsiFactory import org.jetbrains.kotlin.psi.JetPsiUtil import org.jetbrains.kotlin.psi.JetThrowExpression -public class DoubleBangToIfThenIntention : JetSelfTargetingIntention(javaClass(), "Replace '!!' expression with 'if' expression") { - override fun isApplicableTo(element: JetPostfixExpression, caretOffset: Int): Boolean { - return element.getOperationToken() == JetTokens.EXCLEXCL && element.getOperationReference().getTextRange().containsOffset(caretOffset) +public class DoubleBangToIfThenIntention : JetSelfTargetingRangeIntention(javaClass(), "Replace '!!' expression with 'if' expression") { + override fun applicabilityRange(element: JetPostfixExpression): TextRange? { + return if (element.getOperationToken() == JetTokens.EXCLEXCL) element.getOperationReference().getTextRange() else null } override fun applyTo(element: JetPostfixExpression, editor: Editor) { diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/IfToWhenIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/IfToWhenIntention.kt index b3e1a954234..3900ce6942c 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/IfToWhenIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/IfToWhenIntention.kt @@ -17,17 +17,18 @@ package org.jetbrains.kotlin.idea.intentions.branchedTransformations.intentions import com.intellij.openapi.editor.Editor -import org.jetbrains.kotlin.idea.intentions.JetSelfTargetingIntention +import com.intellij.openapi.util.TextRange +import org.jetbrains.kotlin.idea.intentions.JetSelfTargetingRangeIntention import org.jetbrains.kotlin.idea.intentions.branchedTransformations.getSubjectToIntroduce import org.jetbrains.kotlin.idea.intentions.branchedTransformations.introduceSubject import org.jetbrains.kotlin.lexer.JetTokens import org.jetbrains.kotlin.psi.* import java.util.ArrayList -public class IfToWhenIntention : JetSelfTargetingIntention(javaClass(), "Replace 'if' with 'when'") { - override fun isApplicableTo(element: JetIfExpression, caretOffset: Int): Boolean { - if (element.getThen() == null) return false - return element.getIfKeyword().getTextRange().containsOffset(caretOffset) +public class IfToWhenIntention : JetSelfTargetingRangeIntention(javaClass(), "Replace 'if' with 'when'") { + override fun applicabilityRange(element: JetIfExpression): TextRange? { + if (element.getThen() == null) return null + return element.getIfKeyword().getTextRange() } override fun applyTo(element: JetIfExpression, editor: Editor) {