This commit is contained in:
Valentin Kipyatkov
2015-05-11 16:49:50 +03:00
parent ea168b0f6b
commit b94d6306a7
2 changed files with 11 additions and 9 deletions
@@ -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<JetPostfixExpression>(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<JetPostfixExpression>(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) {
@@ -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<JetIfExpression>(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<JetIfExpression>(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) {