diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/inspections/IntentionBasedInspection.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/inspections/IntentionBasedInspection.kt index bdfc14b4748..e74c68e606a 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/inspections/IntentionBasedInspection.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/inspections/IntentionBasedInspection.kt @@ -16,22 +16,18 @@ package org.jetbrains.kotlin.idea.inspections -import com.intellij.psi.PsiElement -import org.jetbrains.kotlin.psi.JetElement -import com.intellij.psi.PsiElementVisitor -import com.intellij.codeInspection.LocalInspectionToolSession -import com.intellij.codeInspection.ProblemsHolder -import com.intellij.codeInspection.ProblemHighlightType -import com.intellij.codeInspection.LocalQuickFix -import com.intellij.openapi.project.Project -import com.intellij.codeInspection.ProblemDescriptor -import org.jetbrains.kotlin.idea.intentions.JetSelfTargetingIntention -import com.intellij.openapi.fileEditor.FileDocumentManager -import com.intellij.openapi.editor.EditorFactory +import com.intellij.codeInspection.* import com.intellij.openapi.editor.Editor +import com.intellij.openapi.editor.EditorFactory +import com.intellij.openapi.fileEditor.FileDocumentManager +import com.intellij.openapi.project.Project +import com.intellij.psi.PsiElement +import com.intellij.psi.PsiElementVisitor +import org.jetbrains.kotlin.idea.intentions.JetSelfTargetingOffsetIndependentIntention +import org.jetbrains.kotlin.psi.JetElement public abstract class IntentionBasedInspection( - protected val intention: JetSelfTargetingIntention + protected val intention: JetSelfTargetingOffsetIndependentIntention ) : AbstractKotlinInspection() { override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean, session: LocalInspectionToolSession): PsiElementVisitor { return object: PsiElementVisitor() { @@ -70,11 +66,8 @@ public abstract class IntentionBasedInspection( } private fun PsiElement.getOrCreateEditor(): Editor? { - val file = getContainingFile()?.getVirtualFile() - if (file == null) return null - - val document = FileDocumentManager.getInstance()!!.getDocument(file) - if (document == null) return null + val file = getContainingFile()?.getVirtualFile() ?: return null + val document = FileDocumentManager.getInstance().getDocument(file) ?: return null val editorFactory = EditorFactory.getInstance()!! diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/intentions/JetSelfTargetingIntention.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/intentions/JetSelfTargetingIntention.kt index 3a56325e5cb..3d9e846a6c3 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/intentions/JetSelfTargetingIntention.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/intentions/JetSelfTargetingIntention.kt @@ -37,27 +37,42 @@ public abstract class JetSelfTargetingIntention( this.text = text } - override fun getText() = text - override fun getFamilyName() = familyName + final override fun getText() = text + final override fun getFamilyName() = familyName + + public abstract fun isApplicableTo(element: T, caretOffset: Int): Boolean - public abstract fun isApplicableTo(element: T): Boolean - public open fun isApplicableTo(element: T, editor: Editor): Boolean = isApplicableTo(element) public abstract fun applyTo(element: T, editor: Editor) - protected fun getTarget(editor: Editor, file: PsiFile): T? { + private fun getTarget(editor: Editor, file: PsiFile): T? { val offset = editor.getCaretModel().getOffset() - return file.findElementAt(offset)?.getParentOfTypesAndPredicate(false, elementType) { element -> isApplicableTo(element, editor) } + return file.findElementAt(offset)?.getParentOfTypesAndPredicate(false, elementType) { element -> isApplicableTo(element, offset) } } - override fun isAvailable(project: Project, editor: Editor, file: PsiFile) + final override fun isAvailable(project: Project, editor: Editor, file: PsiFile) = getTarget(editor, file) != null - override fun invoke(project: Project, editor: Editor, file: PsiFile): Unit { + final override fun invoke(project: Project, editor: Editor, file: PsiFile): Unit { val target = getTarget(editor, file) ?: error("Intention is not applicable") applyTo(target, editor) } - override fun startInWriteAction(): Boolean = true + override fun startInWriteAction() = true override fun toString(): String = getText() } + +public abstract class JetSelfTargetingOffsetIndependentIntention( + elementType: Class, + text: String, + familyName: String) +: JetSelfTargetingIntention(elementType, text, familyName) { + + deprecated("Use primary constructor, no need to use i18n") + public constructor(key: String, elementType: Class) : this(elementType, JetBundle.message(key), JetBundle.message(key + ".family")) { + } + + public abstract fun isApplicableTo(element: T): Boolean + + override final fun isApplicableTo(element: T, caretOffset: Int): Boolean = isApplicableTo(element) +} diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/intentions/OperatorToFunctionIntention.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/intentions/OperatorToFunctionIntention.kt index 7c0d1be7f61..ca60befe9c4 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/intentions/OperatorToFunctionIntention.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/intentions/OperatorToFunctionIntention.kt @@ -32,7 +32,7 @@ import org.jetbrains.kotlin.descriptors.FunctionDescriptor import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall import org.jetbrains.kotlin.idea.caches.resolve.analyze -public class OperatorToFunctionIntention : JetSelfTargetingIntention("operator.to.function", javaClass()) { +public class OperatorToFunctionIntention : JetSelfTargetingOffsetIndependentIntention("operator.to.function", javaClass()) { companion object { private fun isApplicablePrefix(element: JetPrefixExpression): Boolean { return when (element.getOperationReference().getReferencedNameElementType()) { diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/intentions/RemoveExplicitTypeArguments.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/intentions/RemoveExplicitTypeArguments.kt index 594fdf2ec5b..cdf381b997f 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/intentions/RemoveExplicitTypeArguments.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/intentions/RemoveExplicitTypeArguments.kt @@ -37,7 +37,7 @@ import org.jetbrains.kotlin.idea.util.approximateFlexibleTypes import org.jetbrains.kotlin.idea.caches.resolve.findModuleDescriptor import org.jetbrains.kotlin.idea.caches.resolve.analyze -public class RemoveExplicitTypeArguments : JetSelfTargetingIntention( +public class RemoveExplicitTypeArguments : JetSelfTargetingOffsetIndependentIntention( "remove.explicit.type.arguments", javaClass()) { override fun isApplicableTo(element: JetTypeArgumentList): Boolean { diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/intentions/SimplifyNegatedBinaryExpressionIntention.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/intentions/SimplifyNegatedBinaryExpressionIntention.kt index 2a0365ca414..35e8327c754 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/intentions/SimplifyNegatedBinaryExpressionIntention.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/intentions/SimplifyNegatedBinaryExpressionIntention.kt @@ -30,7 +30,7 @@ import org.jetbrains.kotlin.psi.JetPsiUtil import org.jetbrains.kotlin.idea.JetBundle import org.jetbrains.kotlin.psi.JetPsiFactory -public class SimplifyNegatedBinaryExpressionIntention : JetSelfTargetingIntention("simplify.negated.binary.expression", javaClass()) { +public class SimplifyNegatedBinaryExpressionIntention : JetSelfTargetingOffsetIndependentIntention("simplify.negated.binary.expression", javaClass()) { private fun JetPrefixExpression.unparenthesize(): JetExpression? { return (this.getBaseExpression() as? JetParenthesizedExpression)?.getExpression() diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/AddBracesIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/AddBracesIntention.kt index f3f78a33360..7761b68b2cf 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/AddBracesIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/AddBracesIntention.kt @@ -24,16 +24,10 @@ import org.jetbrains.kotlin.JetNodeTypes import com.intellij.psi.PsiWhiteSpace public class AddBracesIntention : JetSelfTargetingIntention("add.braces", javaClass()) { - override fun isApplicableTo(element: JetExpressionImpl): Boolean { - throw IllegalStateException("isApplicableTo(JetExpressionImpl, Editor) should be called instead") - } + override fun isApplicableTo(element: JetExpressionImpl, caretOffset: Int): Boolean { + val expressionKind = element.getExpressionKind(caretOffset) ?: return false - override fun isApplicableTo(element: JetExpressionImpl, editor: Editor): Boolean { - val expressionKind = element.getExpressionKind(editor.getCaretModel().getOffset()) - if (expressionKind == null) return false - - val jetBlockElement = element.findBlockInExpression(expressionKind) - if (jetBlockElement != null) return false + if (element.findBlockInExpression(expressionKind) != null) return false setText("Add braces to '${expressionKind.text}' statement") return true diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertAssertToIfWithThrowIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertAssertToIfWithThrowIntention.kt index 76d70cc49bf..1b97f70b372 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertAssertToIfWithThrowIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertAssertToIfWithThrowIntention.kt @@ -33,7 +33,7 @@ import org.jetbrains.kotlin.psi.JetThrowExpression import org.jetbrains.kotlin.psi.psiUtil.replaced import org.jetbrains.kotlin.idea.caches.resolve.analyze -public class ConvertAssertToIfWithThrowIntention : JetSelfTargetingIntention( +public class ConvertAssertToIfWithThrowIntention : JetSelfTargetingOffsetIndependentIntention( "convert.assert.to.if.with.throw", javaClass()) { private var messageIsAFunction : Boolean by Delegates.notNull() diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertFunctionToPropertyIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertFunctionToPropertyIntention.kt index 8175ca2f6d9..86688a37153 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertFunctionToPropertyIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertFunctionToPropertyIntention.kt @@ -190,12 +190,8 @@ public class ConvertFunctionToPropertyIntention : JetSelfTargetingIntention("convert.if.with.throw.to.assert", javaClass()) { + JetSelfTargetingOffsetIndependentIntention("convert.if.with.throw.to.assert", javaClass()) { override fun isApplicableTo(element: JetIfExpression): Boolean { if (element.getElse() != null) return false diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertNegatedBooleanSequenceIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertNegatedBooleanSequenceIntention.kt index 588a08e4082..c88082f04b4 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertNegatedBooleanSequenceIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertNegatedBooleanSequenceIntention.kt @@ -26,7 +26,7 @@ import org.jetbrains.kotlin.psi.JetPsiUtil import java.util.LinkedList -public class ConvertNegatedBooleanSequenceIntention : JetSelfTargetingIntention( +public class ConvertNegatedBooleanSequenceIntention : JetSelfTargetingOffsetIndependentIntention( "convert.negated.boolean.sequence", javaClass()) { override fun isApplicableTo(element: JetBinaryExpression): Boolean { diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertNegatedExpressionWithDemorgansLawIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertNegatedExpressionWithDemorgansLawIntention.kt index 29e725ed036..0a1cecc49b6 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertNegatedExpressionWithDemorgansLawIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertNegatedExpressionWithDemorgansLawIntention.kt @@ -29,7 +29,7 @@ import org.jetbrains.kotlin.psi.JetSimpleNameExpression import java.util.LinkedList import org.jetbrains.kotlin.idea.JetBundle -public class ConvertNegatedExpressionWithDemorgansLawIntention : JetSelfTargetingIntention( +public class ConvertNegatedExpressionWithDemorgansLawIntention : JetSelfTargetingOffsetIndependentIntention( "convert.negated.expression.with.demorgans.law", javaClass() ) { diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertParameterToReceiverIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertParameterToReceiverIntention.kt index 5f40c6e6b95..185f20c56d7 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertParameterToReceiverIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertParameterToReceiverIntention.kt @@ -29,7 +29,7 @@ import org.jetbrains.kotlin.idea.refactoring.changeSignature.JetMethodDescriptor import org.jetbrains.kotlin.idea.refactoring.changeSignature.modify import org.jetbrains.kotlin.idea.caches.resolve.analyzeFully -public class ConvertParameterToReceiverIntention: JetSelfTargetingIntention("convert.parameter.to.receiver.intention", javaClass()) { +public class ConvertParameterToReceiverIntention: JetSelfTargetingOffsetIndependentIntention("convert.parameter.to.receiver.intention", javaClass()) { override fun isApplicableTo(element: JetParameter): Boolean { if (element.isVarArg()) return false val function = element.getStrictParentOfType() ?: return false diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertPropertyToFunctionIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertPropertyToFunctionIntention.kt index de602768ef8..8a9e49340f2 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertPropertyToFunctionIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertPropertyToFunctionIntention.kt @@ -182,12 +182,8 @@ public class ConvertPropertyToFunctionIntention : JetSelfTargetingIntention("convert.receiver.to.parameter.intention", javaClass()) { +public class ConvertReceiverToParameterIntention: JetSelfTargetingOffsetIndependentIntention("convert.receiver.to.parameter.intention", javaClass()) { override fun isApplicableTo(element: JetTypeReference): Boolean { return (element.getParent() as? JetNamedFunction)?.getReceiverTypeReference() == element } diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertToConcatenatedStringIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertToConcatenatedStringIntention.kt index c518e1dd3e7..f2e6433ab52 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertToConcatenatedStringIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertToConcatenatedStringIntention.kt @@ -29,7 +29,7 @@ import org.jetbrains.kotlin.psi.JetIfExpression import org.jetbrains.kotlin.psi.JetBlockExpression import org.jetbrains.kotlin.idea.caches.resolve.analyze -public class ConvertToConcatenatedStringIntention : JetSelfTargetingIntention("convert.to.concatenated.string.intention", javaClass()) { +public class ConvertToConcatenatedStringIntention : JetSelfTargetingOffsetIndependentIntention("convert.to.concatenated.string.intention", javaClass()) { override fun isApplicableTo(element: JetStringTemplateExpression): Boolean { return element.getEntries().any { it is JetStringTemplateEntryWithExpression } } diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertToForEachFunctionCallIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertToForEachFunctionCallIntention.kt index d69125e8e63..1dabebf0843 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertToForEachFunctionCallIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertToForEachFunctionCallIntention.kt @@ -24,7 +24,7 @@ import org.jetbrains.kotlin.psi.JetElement import org.jetbrains.kotlin.psi.JetParameter import org.jetbrains.kotlin.psi.JetOperationExpression -public class ConvertToForEachFunctionCallIntention : JetSelfTargetingIntention("convert.to.for.each.function.call.intention", javaClass()) { +public class ConvertToForEachFunctionCallIntention : JetSelfTargetingOffsetIndependentIntention("convert.to.for.each.function.call.intention", javaClass()) { override fun isApplicableTo(element: JetForExpression): Boolean { return element.getLoopRange() != null && element.getLoopParameter() != null && element.getBody() != null } diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertToForEachLoopIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertToForEachLoopIntention.kt index 0af08cacda7..99422f3bfe0 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertToForEachLoopIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertToForEachLoopIntention.kt @@ -28,7 +28,7 @@ import org.jetbrains.kotlin.psi.JetParenthesizedExpression import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall import org.jetbrains.kotlin.idea.caches.resolve.analyze -public class ConvertToForEachLoopIntention : JetSelfTargetingIntention("convert.to.for.each.loop.intention", javaClass()) { +public class ConvertToForEachLoopIntention : JetSelfTargetingOffsetIndependentIntention("convert.to.for.each.loop.intention", javaClass()) { private fun getFunctionLiteralArgument(element: JetExpression): JetFunctionLiteralExpression? { val argument = when (element) { is JetDotQualifiedExpression -> { diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertToStringTemplateIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertToStringTemplateIntention.kt index ac05b85fc98..03c4105b40f 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertToStringTemplateIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertToStringTemplateIntention.kt @@ -35,7 +35,7 @@ import org.jetbrains.kotlin.builtins.KotlinBuiltIns import org.jetbrains.kotlin.idea.caches.resolve.analyze -public class ConvertToStringTemplateIntention : JetSelfTargetingIntention("convert.to.string.template", javaClass()) { +public class ConvertToStringTemplateIntention : JetSelfTargetingOffsetIndependentIntention("convert.to.string.template", javaClass()) { override fun isApplicableTo(element: JetBinaryExpression): Boolean { if (element.getOperationToken() != JetTokens.PLUS) return false diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/InsertCurlyBracesToTemplateIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/InsertCurlyBracesToTemplateIntention.kt index 1b035ad48d5..f7a4b81dd77 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/InsertCurlyBracesToTemplateIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/InsertCurlyBracesToTemplateIntention.kt @@ -20,7 +20,7 @@ import com.intellij.openapi.editor.Editor import org.jetbrains.kotlin.psi.JetSimpleNameStringTemplateEntry import org.jetbrains.kotlin.psi.JetPsiFactory -public class InsertCurlyBracesToTemplateIntention : JetSelfTargetingIntention( +public class InsertCurlyBracesToTemplateIntention : JetSelfTargetingOffsetIndependentIntention( "insert.curly.brackets.to.string.template", javaClass()) { override fun isApplicableTo(element: JetSimpleNameStringTemplateEntry): Boolean = true diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/InsertExplicitTypeArguments.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/InsertExplicitTypeArguments.kt index 00cf06e66af..4bcbc764a13 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/InsertExplicitTypeArguments.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/InsertExplicitTypeArguments.kt @@ -29,16 +29,12 @@ import org.jetbrains.kotlin.idea.caches.resolve.analyze public class InsertExplicitTypeArguments : JetSelfTargetingIntention( "insert.explicit.type.arguments", javaClass()) { - override fun isApplicableTo(element: JetCallExpression): Boolean { - throw IllegalStateException("isApplicableTo(JetExpressionImpl, Editor) should be called instead") - } - - override fun isApplicableTo(element: JetCallExpression, editor: Editor): Boolean { + override fun isApplicableTo(element: JetCallExpression, caretOffset: Int): Boolean { if (!element.getTypeArguments().isEmpty()) return false if (element.getText() == null) return false val textRange = element.getCalleeExpression()?.getTextRange() - if (textRange == null || !textRange.contains(editor.getCaretModel().getOffset())) return false + if (textRange == null || !textRange.contains(caretOffset)) return false val context = element.analyze() val resolvedCall = element.getResolvedCall(context) diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/InvertIfConditionIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/InvertIfConditionIntention.kt index c38ee922ccd..083f40c3a5e 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/InvertIfConditionIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/InvertIfConditionIntention.kt @@ -33,7 +33,7 @@ import org.jetbrains.kotlin.lexer.JetKeywordToken import org.jetbrains.kotlin.psi.JetNamedFunction import org.jetbrains.kotlin.psi.JetBlockExpression -public class InvertIfConditionIntention : JetSelfTargetingIntention("invert.if.condition", javaClass()) { +public class InvertIfConditionIntention : JetSelfTargetingOffsetIndependentIntention("invert.if.condition", javaClass()) { fun checkForNegation(element: JetUnaryExpression): Boolean { return element.getOperationReference().getReferencedName().equals("!") } diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/MakeTypeExplicitInLambdaIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/MakeTypeExplicitInLambdaIntention.kt index 271f9361d9e..51ccd3a6a6a 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/MakeTypeExplicitInLambdaIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/MakeTypeExplicitInLambdaIntention.kt @@ -29,18 +29,13 @@ import org.jetbrains.kotlin.idea.caches.resolve.analyze public class MakeTypeExplicitInLambdaIntention : JetSelfTargetingIntention( "make.type.explicit.in.lambda", javaClass()) { - override fun isApplicableTo(element: JetFunctionLiteralExpression): Boolean { - throw IllegalStateException("isApplicableTo(JetExpressionImpl, Editor) should be called instead") - } - - override fun isApplicableTo(element: JetFunctionLiteralExpression, editor: Editor): Boolean { + override fun isApplicableTo(element: JetFunctionLiteralExpression, caretOffset: Int): Boolean { val openBraceOffset = element.getLeftCurlyBrace().getStartOffset() val closeBraceOffset = element.getRightCurlyBrace()?.getStartOffset() - val caretLocation = editor.getCaretModel().getOffset() val arrow = element.getFunctionLiteral().getArrowNode() - if (arrow != null && !(openBraceOffset < caretLocation && caretLocation < arrow.getStartOffset() + 2) && - caretLocation != closeBraceOffset) return false - else if (arrow == null && caretLocation != openBraceOffset + 1 && caretLocation != closeBraceOffset) return false + if (arrow != null && !(openBraceOffset < caretOffset && caretOffset < arrow.getStartOffset() + 2) && + caretOffset != closeBraceOffset) return false + else if (arrow == null && caretOffset != openBraceOffset + 1 && caretOffset != closeBraceOffset) return false val context = element.analyze() val func = context[BindingContext.FUNCTION, element.getFunctionLiteral()] diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/MakeTypeImplicitInLambdaIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/MakeTypeImplicitInLambdaIntention.kt index b92b9da6221..e6c9999cd3a 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/MakeTypeImplicitInLambdaIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/MakeTypeImplicitInLambdaIntention.kt @@ -23,18 +23,13 @@ import org.jetbrains.kotlin.lexer.JetTokens public class MakeTypeImplicitInLambdaIntention : JetSelfTargetingIntention( "make.type.implicit.in.lambda", javaClass()) { - override fun isApplicableTo(element: JetFunctionLiteralExpression): Boolean { - throw IllegalStateException("isApplicableTo(JetExpressionImpl, Editor) should be called instead") - } - - override fun isApplicableTo(element: JetFunctionLiteralExpression, editor: Editor): Boolean { + override fun isApplicableTo(element: JetFunctionLiteralExpression, caretOffset: Int): Boolean { val openBraceOffset = element.getLeftCurlyBrace().getStartOffset() val closeBraceOffset = element.getRightCurlyBrace()?.getStartOffset() - val caretLocation = editor.getCaretModel().getOffset() val arrow = element.getFunctionLiteral().getArrowNode() - if (arrow != null && !(openBraceOffset < caretLocation && caretLocation < arrow.getStartOffset() + 2) && - caretLocation != closeBraceOffset) return false - else if (arrow == null && caretLocation != openBraceOffset + 1 && caretLocation != closeBraceOffset) return false + if (arrow != null && !(openBraceOffset < caretOffset && caretOffset < arrow.getStartOffset() + 2) && + caretOffset != closeBraceOffset) return false + else if (arrow == null && caretOffset != openBraceOffset + 1 && caretOffset != closeBraceOffset) return false return hasExplicitReturnType(element) || hasExplicitReceiverType(element) || hasExplicitParamType(element) } diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/MoveLambdaInsideParenthesesIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/MoveLambdaInsideParenthesesIntention.kt index 6ad32f18e6c..64c50ba19bf 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/MoveLambdaInsideParenthesesIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/MoveLambdaInsideParenthesesIntention.kt @@ -21,7 +21,7 @@ import org.jetbrains.kotlin.psi.JetFunctionLiteralArgument import org.jetbrains.kotlin.idea.util.psiModificationUtil.moveInsideParentheses import org.jetbrains.kotlin.idea.caches.resolve.analyzeFully -public class MoveLambdaInsideParenthesesIntention : JetSelfTargetingIntention( +public class MoveLambdaInsideParenthesesIntention : JetSelfTargetingOffsetIndependentIntention( "move.lambda.inside.parentheses", javaClass()) { override fun isApplicableTo(element: JetFunctionLiteralArgument): Boolean = true diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/MoveLambdaOutsideParenthesesIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/MoveLambdaOutsideParenthesesIntention.kt index 07229237285..c7cee2909f6 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/MoveLambdaOutsideParenthesesIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/MoveLambdaOutsideParenthesesIntention.kt @@ -25,7 +25,7 @@ import org.jetbrains.kotlin.psi.JetExpression import org.jetbrains.kotlin.psi.JetLabeledExpression import org.jetbrains.kotlin.resolve.calls.callUtil.getValueArgumentsInParentheses -public class MoveLambdaOutsideParenthesesIntention : JetSelfTargetingIntention( +public class MoveLambdaOutsideParenthesesIntention : JetSelfTargetingOffsetIndependentIntention( "move.lambda.outside.parentheses", javaClass()) { private fun isLambdaOrLabeledLambda(expression: JetExpression?): Boolean = diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveBracesIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveBracesIntention.kt index 0e9fcc1eb52..38db8edf2f8 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveBracesIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveBracesIntention.kt @@ -24,16 +24,10 @@ import com.intellij.psi.PsiWhiteSpace import com.intellij.psi.PsiComment public class RemoveBracesIntention : JetSelfTargetingIntention("remove.braces", javaClass()) { - override fun isApplicableTo(element: JetExpressionImpl): Boolean { - throw IllegalStateException("isApplicableTo(JetExpressionImpl, Editor) should be called instead") - } + override fun isApplicableTo(element: JetExpressionImpl, caretOffset: Int): Boolean { + val expressionKind = element.getExpressionKind(caretOffset) ?: return false - override fun isApplicableTo(element: JetExpressionImpl, editor: Editor): Boolean { - val expressionKind = element.getExpressionKind(editor.getCaretModel().getOffset()) - if (expressionKind == null) return false - - val jetBlockElement = element.findBlockInExpression(expressionKind) - if (jetBlockElement == null) return false + val jetBlockElement = element.findBlockInExpression(expressionKind) ?: return false if (jetBlockElement.getStatements().size == 1) { setText("Remove braces from '${expressionKind.text}' statement") diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveCurlyBracesFromTemplateIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveCurlyBracesFromTemplateIntention.kt index aef5eb26e19..1f8c16a4190 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveCurlyBracesFromTemplateIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveCurlyBracesFromTemplateIntention.kt @@ -23,7 +23,7 @@ import org.jetbrains.kotlin.psi.JetPsiFactory import java.util.regex.* import org.jetbrains.kotlin.psi.JetStringTemplateEntryWithExpression -public class RemoveCurlyBracesFromTemplateIntention : JetSelfTargetingIntention( +public class RemoveCurlyBracesFromTemplateIntention : JetSelfTargetingOffsetIndependentIntention( "remove.unnecessary.curly.brackets.from.string.template", javaClass()) { companion object { diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveUnnecessaryParenthesesIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveUnnecessaryParenthesesIntention.kt index 5d01a8b4975..84e1db9d7d3 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveUnnecessaryParenthesesIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveUnnecessaryParenthesesIntention.kt @@ -20,7 +20,7 @@ import com.intellij.openapi.editor.Editor import org.jetbrains.kotlin.psi.JetParenthesizedExpression import org.jetbrains.kotlin.psi.JetPsiUtil -public class RemoveUnnecessaryParenthesesIntention : JetSelfTargetingIntention( +public class RemoveUnnecessaryParenthesesIntention : JetSelfTargetingOffsetIndependentIntention( "remove.unnecessary.parentheses", javaClass() ) { override fun isApplicableTo(element: JetParenthesizedExpression): Boolean = JetPsiUtil.areParenthesesUseless(element) diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/ReplaceWithDotQualifiedMethodCallIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/ReplaceWithDotQualifiedMethodCallIntention.kt index 673ea138143..665ed2a6e9f 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/ReplaceWithDotQualifiedMethodCallIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/ReplaceWithDotQualifiedMethodCallIntention.kt @@ -23,7 +23,7 @@ import org.jetbrains.kotlin.psi.JetFunctionLiteralExpression import org.jetbrains.kotlin.psi.JetParenthesizedExpression import org.jetbrains.kotlin.lexer.JetTokens -public class ReplaceWithDotQualifiedMethodCallIntention : JetSelfTargetingIntention("replace.with.dot.qualified.method.call.intention", javaClass()) { +public class ReplaceWithDotQualifiedMethodCallIntention : JetSelfTargetingOffsetIndependentIntention("replace.with.dot.qualified.method.call.intention", javaClass()) { override fun isApplicableTo(element: JetBinaryExpression): Boolean { return element.getLeft() != null && element.getRight() != null && element.getOperationToken() == JetTokens.IDENTIFIER } diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/ReplaceWithInfixFunctionCallIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/ReplaceWithInfixFunctionCallIntention.kt index 8339445cbc4..f53593e9371 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/ReplaceWithInfixFunctionCallIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/ReplaceWithInfixFunctionCallIntention.kt @@ -30,20 +30,14 @@ import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall import org.jetbrains.kotlin.idea.caches.resolve.analyze public open class ReplaceWithInfixFunctionCallIntention : JetSelfTargetingIntention("replace.with.infix.function.call.intention", javaClass()) { - override fun isApplicableTo(element: JetCallExpression): Boolean { - throw IllegalStateException("isApplicableTo(JetExpressionImpl, Editor) should be called instead") - } - - override fun isApplicableTo(element: JetCallExpression, editor: Editor): Boolean { - val caretLocation = editor.getCaretModel().getOffset() - + override fun isApplicableTo(element: JetCallExpression, caretOffset: Int): Boolean { val calleeExpr = element.getCalleeExpression() if (calleeExpr == null) return false val textRange = calleeExpr.getTextRange() if (textRange == null) return false - if (caretLocation !in textRange) return false + if (caretOffset !in textRange) return false val parent = element.getParent() diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/ReplaceWithOperatorAssignIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/ReplaceWithOperatorAssignIntention.kt index 0443f313bca..ada3a37b0b7 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/ReplaceWithOperatorAssignIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/ReplaceWithOperatorAssignIntention.kt @@ -27,7 +27,7 @@ import org.jetbrains.kotlin.builtins.KotlinBuiltIns import org.jetbrains.kotlin.idea.util.psi.patternMatching.matches import org.jetbrains.kotlin.idea.caches.resolve.analyze -public class ReplaceWithOperatorAssignIntention : JetSelfTargetingIntention("replace.with.operator.assign.intention", javaClass()) { +public class ReplaceWithOperatorAssignIntention : JetSelfTargetingOffsetIndependentIntention("replace.with.operator.assign.intention", javaClass()) { override fun isApplicableTo(element: JetBinaryExpression): Boolean { fun isWellFormedAssignment(element : JetBinaryExpression): Boolean { diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/ReplaceWithTraditionalAssignmentIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/ReplaceWithTraditionalAssignmentIntention.kt index 2ee25f39114..f0cca28ce1c 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/ReplaceWithTraditionalAssignmentIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/ReplaceWithTraditionalAssignmentIntention.kt @@ -23,7 +23,7 @@ import org.jetbrains.kotlin.lexer.JetTokens import org.jetbrains.kotlin.psi.JetPsiFactory import org.jetbrains.kotlin.psi.JetPsiUnparsingUtils -public class ReplaceWithTraditionalAssignmentIntention : JetSelfTargetingIntention("replace.with.traditional.assignment.intention", javaClass()) { +public class ReplaceWithTraditionalAssignmentIntention : JetSelfTargetingOffsetIndependentIntention("replace.with.traditional.assignment.intention", javaClass()) { override fun isApplicableTo(element: JetBinaryExpression): Boolean { fun checkForNullSafety(element: JetBinaryExpression): Boolean = element.getLeft() != null && element.getRight() != null && element.getOperationToken() != null diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/SimplifyBooleanWithConstantsIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/SimplifyBooleanWithConstantsIntention.kt index ec7bed9c430..735e4a9a2a7 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/SimplifyBooleanWithConstantsIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/SimplifyBooleanWithConstantsIntention.kt @@ -30,7 +30,7 @@ import org.jetbrains.kotlin.psi.psiUtil.copied import org.jetbrains.kotlin.psi.psiUtil.replaced import org.jetbrains.kotlin.idea.caches.resolve.analyze -public class SimplifyBooleanWithConstantsIntention : JetSelfTargetingIntention( +public class SimplifyBooleanWithConstantsIntention : JetSelfTargetingOffsetIndependentIntention( "simplify.boolean.with.constants", javaClass()) { private var topParent : JetBinaryExpression? = null diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/SplitIfIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/SplitIfIntention.kt index 6a44cd2991b..0a990e8aa8e 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/SplitIfIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/SplitIfIntention.kt @@ -28,11 +28,7 @@ import org.jetbrains.kotlin.psi.JetExpression import org.jetbrains.kotlin.psi.JetPsiUtil public class SplitIfIntention : JetSelfTargetingIntention("split.if", javaClass()) { - override fun isApplicableTo(element: JetExpression): Boolean { - throw IllegalStateException("isApplicableTo(JetExpression, Editor) should be called instead") - } - - override fun isApplicableTo(element: JetExpression, editor: Editor): Boolean { + override fun isApplicableTo(element: JetExpression, caretOffset: Int): Boolean { if (element !is JetSimpleNameExpression && element !is JetIfExpression) return false if (element is JetSimpleNameExpression) { @@ -40,7 +36,7 @@ public class SplitIfIntention : JetSelfTargetingIntention("split. } if (element is JetIfExpression) { - if (!isCursorOnIfKeyword(element, editor)) return false + if (!isCursorOnIfKeyword(element, caretOffset)) return false if (getFirstValidOperator(element) == null) return false } return true @@ -54,7 +50,7 @@ public class SplitIfIntention : JetSelfTargetingIntention("split. val ifExpression = currentElement!!.getNonStrictParentOfType() val expression = currentElement.getParent() as JetBinaryExpression - val rightExpression = getRight(expression, ifExpression!!.getCondition() as JetExpression) + val rightExpression = getRight(expression, ifExpression!!.getCondition()) val leftExpression = expression.getLeft() val elseExpression = ifExpression.getElse() val thenExpression = ifExpression.getThen() @@ -75,7 +71,7 @@ public class SplitIfIntention : JetSelfTargetingIntention("split. } } - fun getRight(element: JetBinaryExpression, condition: JetExpression): JetExpression { + private fun getRight(element: JetBinaryExpression, condition: JetExpression): JetExpression { //gets the textOffset of the right side of the JetBinaryExpression in context to condition val startOffset = element.getRight()!!.getTextOffset() - condition.getTextOffset() val rightString = condition.getText()!![startOffset, condition.getTextLength()].toString() @@ -83,20 +79,19 @@ public class SplitIfIntention : JetSelfTargetingIntention("split. return JetPsiFactory(element).createExpression(rightString) } - fun isCursorOnIfKeyword(element: JetIfExpression, editor: Editor): Boolean { + private fun isCursorOnIfKeyword(element: JetIfExpression, offset: Int): Boolean { val ifKeyword = JetPsiUtil.findChildByType(element, JetTokens.IF_KEYWORD) ?: return false - val cursor = editor.getCaretModel().getOffset() - return (cursor >= ifKeyword.getTextOffset() && cursor <= ifKeyword.getTextOffset() + ifKeyword.getTextLength()) + return (offset >= ifKeyword.getTextOffset() && offset <= ifKeyword.getTextOffset() + ifKeyword.getTextLength()) } - fun getFirstValidOperator(element: JetIfExpression): JetSimpleNameExpression? { + private fun getFirstValidOperator(element: JetIfExpression): JetSimpleNameExpression? { if (element.getCondition() == null) return null val condition = element.getCondition() val childElements = PsiTreeUtil.findChildrenOfType(condition, javaClass()) return childElements.firstOrNull { isOperatorValid(it) } } - fun isOperatorValid(element: JetSimpleNameExpression): Boolean { + private fun isOperatorValid(element: JetSimpleNameExpression): Boolean { val operator = element.getReferencedNameElementType() if (operator != JetTokens.ANDAND && operator != JetTokens.OROR) return false diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/SwapBinaryExpression.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/SwapBinaryExpression.kt index 1f50e7d1829..8f7bf0c94e4 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/SwapBinaryExpression.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/SwapBinaryExpression.kt @@ -24,7 +24,7 @@ import org.jetbrains.kotlin.idea.util.JetPsiPrecedences import org.jetbrains.kotlin.lexer.JetTokens.* import org.jetbrains.kotlin.types.expressions.OperatorConventions -public class SwapBinaryExpression : JetSelfTargetingIntention( +public class SwapBinaryExpression : JetSelfTargetingOffsetIndependentIntention( "swap.binary.expression", javaClass() ) { companion object { diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/attributeCallReplacements/AttributeCallReplacementIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/attributeCallReplacements/AttributeCallReplacementIntention.kt index e0d0f82613e..d4f2431e9b6 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/attributeCallReplacements/AttributeCallReplacementIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/attributeCallReplacements/AttributeCallReplacementIntention.kt @@ -16,23 +16,23 @@ package org.jetbrains.kotlin.idea.intentions.attributeCallReplacements -import org.jetbrains.kotlin.psi.JetCallExpression +import com.intellij.codeInsight.hint.HintManager import com.intellij.openapi.editor.Editor -import org.jetbrains.kotlin.psi.JetQualifiedExpression -import org.jetbrains.kotlin.psi.JetDotQualifiedExpression -import org.jetbrains.kotlin.idea.intentions.JetSelfTargetingIntention -import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall import org.jetbrains.kotlin.descriptors.CallableDescriptor -import org.jetbrains.kotlin.psi.ValueArgument import org.jetbrains.kotlin.idea.JetBundle -import org.jetbrains.kotlin.resolve.calls.model.DefaultValueArgument -import org.jetbrains.kotlin.resolve.calls.model.VarargValueArgument +import org.jetbrains.kotlin.idea.caches.resolve.analyze +import org.jetbrains.kotlin.idea.intentions.JetSelfTargetingOffsetIndependentIntention import org.jetbrains.kotlin.idea.util.Maybe import org.jetbrains.kotlin.idea.util.MaybeError import org.jetbrains.kotlin.idea.util.MaybeValue -import com.intellij.codeInsight.hint.HintManager +import org.jetbrains.kotlin.psi.JetCallExpression +import org.jetbrains.kotlin.psi.JetDotQualifiedExpression +import org.jetbrains.kotlin.psi.JetQualifiedExpression +import org.jetbrains.kotlin.psi.ValueArgument import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall -import org.jetbrains.kotlin.idea.caches.resolve.analyze +import org.jetbrains.kotlin.resolve.calls.model.DefaultValueArgument +import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall +import org.jetbrains.kotlin.resolve.calls.model.VarargValueArgument // Internal because you shouldn't construct this manually. You can end up with an inconsistant CallDescription. public class CallDescription internal ( @@ -97,7 +97,7 @@ public fun JetQualifiedExpression.toCallDescription(): CallDescription? { return CallDescription(this, callExpression, resolvedCall) } -public abstract class AttributeCallReplacementIntention(private val name: String) : JetSelfTargetingIntention(name, javaClass()) { +public abstract class AttributeCallReplacementIntention(private val name: String) : JetSelfTargetingOffsetIndependentIntention(name, javaClass()) { protected abstract fun isApplicableToCall(call: CallDescription): Boolean 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 a46b832c2ab..7e52c6b3dd1 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 @@ -16,30 +16,24 @@ package org.jetbrains.kotlin.idea.intentions.branchedTransformations.intentions -import org.jetbrains.kotlin.idea.intentions.JetSelfTargetingIntention -import com.intellij.openapi.editor.Editor -import org.jetbrains.kotlin.lexer.JetTokens -import org.jetbrains.kotlin.psi.JetPsiUtil -import org.jetbrains.kotlin.psi.JetPostfixExpression -import org.jetbrains.kotlin.idea.intentions.branchedTransformations.isStableVariable -import org.jetbrains.kotlin.idea.intentions.JetTypeLookupExpression +import com.intellij.codeInsight.template.Template +import com.intellij.codeInsight.template.TemplateBuilderImpl import com.intellij.codeInsight.template.TemplateEditingAdapter import com.intellij.codeInsight.template.impl.TemplateManagerImpl -import com.intellij.codeInsight.template.Template -import org.jetbrains.kotlin.idea.JetBundle -import org.jetbrains.kotlin.idea.intentions.branchedTransformations.convertToIfNotNullExpression -import org.jetbrains.kotlin.psi.JetPsiFactory -import org.jetbrains.kotlin.idea.intentions.branchedTransformations.introduceValueForCondition -import org.jetbrains.kotlin.psi.JetThrowExpression -import com.intellij.codeInsight.template.TemplateBuilderImpl +import com.intellij.openapi.editor.Editor import com.intellij.psi.PsiDocumentManager import org.apache.commons.lang.StringEscapeUtils.escapeJava -import org.jetbrains.kotlin.idea.intentions.branchedTransformations.convertToIfNullExpression -import org.jetbrains.kotlin.idea.intentions.branchedTransformations.NULL_PTR_EXCEPTION -import org.jetbrains.kotlin.idea.intentions.branchedTransformations.KOTLIN_NULL_PTR_EXCEPTION -import org.jetbrains.kotlin.idea.intentions.branchedTransformations.isStatement +import org.jetbrains.kotlin.idea.JetBundle +import org.jetbrains.kotlin.idea.intentions.JetSelfTargetingOffsetIndependentIntention +import org.jetbrains.kotlin.idea.intentions.JetTypeLookupExpression +import org.jetbrains.kotlin.idea.intentions.branchedTransformations.* +import org.jetbrains.kotlin.lexer.JetTokens +import org.jetbrains.kotlin.psi.JetPostfixExpression +import org.jetbrains.kotlin.psi.JetPsiFactory +import org.jetbrains.kotlin.psi.JetPsiUtil +import org.jetbrains.kotlin.psi.JetThrowExpression -public class DoubleBangToIfThenIntention : JetSelfTargetingIntention("double.bang.to.if.then", javaClass()) { +public class DoubleBangToIfThenIntention : JetSelfTargetingOffsetIndependentIntention("double.bang.to.if.then", javaClass()) { override fun isApplicableTo(element: JetPostfixExpression): Boolean = element.getOperationToken() == JetTokens.EXCLEXCL diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/EliminateWhenSubjectIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/EliminateWhenSubjectIntention.kt index 53ebdc432de..35424125c04 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/EliminateWhenSubjectIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/EliminateWhenSubjectIntention.kt @@ -16,12 +16,13 @@ package org.jetbrains.kotlin.idea.intentions.branchedTransformations.intentions -import org.jetbrains.kotlin.idea.intentions.JetSelfTargetingIntention -import org.jetbrains.kotlin.idea.intentions.branchedTransformations.* -import org.jetbrains.kotlin.psi.JetWhenExpression import com.intellij.openapi.editor.Editor +import org.jetbrains.kotlin.idea.intentions.JetSelfTargetingOffsetIndependentIntention +import org.jetbrains.kotlin.idea.intentions.branchedTransformations.canEliminateSubject +import org.jetbrains.kotlin.idea.intentions.branchedTransformations.eliminateSubject +import org.jetbrains.kotlin.psi.JetWhenExpression -public class EliminateWhenSubjectIntention : JetSelfTargetingIntention("eliminate.when.subject", javaClass()) { +public class EliminateWhenSubjectIntention : JetSelfTargetingOffsetIndependentIntention("eliminate.when.subject", javaClass()) { override fun isApplicableTo(element: JetWhenExpression): Boolean = element.canEliminateSubject() override fun applyTo(element: JetWhenExpression, editor: Editor) { diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/ElvisToIfThenIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/ElvisToIfThenIntention.kt index a391b380804..ec2007f609a 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/ElvisToIfThenIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/ElvisToIfThenIntention.kt @@ -16,16 +16,16 @@ package org.jetbrains.kotlin.idea.intentions.branchedTransformations.intentions -import org.jetbrains.kotlin.psi.JetBinaryExpression -import org.jetbrains.kotlin.idea.intentions.JetSelfTargetingIntention import com.intellij.openapi.editor.Editor -import org.jetbrains.kotlin.lexer.JetTokens -import org.jetbrains.kotlin.psi.JetPsiUtil +import org.jetbrains.kotlin.idea.intentions.JetSelfTargetingOffsetIndependentIntention 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.lexer.JetTokens +import org.jetbrains.kotlin.psi.JetBinaryExpression +import org.jetbrains.kotlin.psi.JetPsiUtil -public class ElvisToIfThenIntention : JetSelfTargetingIntention("elvis.to.if.then", javaClass()) { +public class ElvisToIfThenIntention : JetSelfTargetingOffsetIndependentIntention("elvis.to.if.then", javaClass()) { override fun isApplicableTo(element: JetBinaryExpression): Boolean = element.getOperationToken() == JetTokens.ELVIS diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/FlattenWhenIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/FlattenWhenIntention.kt index c21ec6058d5..97e6d452c69 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/FlattenWhenIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/FlattenWhenIntention.kt @@ -16,12 +16,13 @@ package org.jetbrains.kotlin.idea.intentions.branchedTransformations.intentions -import org.jetbrains.kotlin.idea.intentions.JetSelfTargetingIntention -import org.jetbrains.kotlin.idea.intentions.branchedTransformations.* -import org.jetbrains.kotlin.psi.JetWhenExpression import com.intellij.openapi.editor.Editor +import org.jetbrains.kotlin.idea.intentions.JetSelfTargetingOffsetIndependentIntention +import org.jetbrains.kotlin.idea.intentions.branchedTransformations.canFlatten +import org.jetbrains.kotlin.idea.intentions.branchedTransformations.flatten +import org.jetbrains.kotlin.psi.JetWhenExpression -public class FlattenWhenIntention : JetSelfTargetingIntention("flatten.when", javaClass()) { +public class FlattenWhenIntention : JetSelfTargetingOffsetIndependentIntention("flatten.when", javaClass()) { override fun isApplicableTo(element: JetWhenExpression): Boolean = element.canFlatten() override fun applyTo(element: JetWhenExpression, editor: Editor) { diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/FoldBranchedExpressionIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/FoldBranchedExpressionIntention.kt index d1527078607..2c17c0cfa03 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/FoldBranchedExpressionIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/FoldBranchedExpressionIntention.kt @@ -16,18 +16,18 @@ package org.jetbrains.kotlin.idea.intentions.branchedTransformations.intentions -import org.jetbrains.kotlin.psi.JetExpression -import org.jetbrains.kotlin.idea.intentions.JetSelfTargetingIntention +import com.intellij.openapi.editor.Editor +import org.jetbrains.kotlin.idea.intentions.JetSelfTargetingOffsetIndependentIntention import org.jetbrains.kotlin.idea.intentions.branchedTransformations.BranchedFoldingUtils import org.jetbrains.kotlin.idea.intentions.branchedTransformations.FoldableKind -import com.intellij.openapi.editor.Editor +import org.jetbrains.kotlin.psi.JetExpression import org.jetbrains.kotlin.psi.JetFile import org.jetbrains.kotlin.psi.JetIfExpression import org.jetbrains.kotlin.psi.JetWhenExpression public open class FoldBranchedExpressionIntention( val kind: FoldableKind, elementType: Class -) : JetSelfTargetingIntention(kind.getKey(), elementType) { +) : JetSelfTargetingOffsetIndependentIntention(kind.getKey(), elementType) { override fun isApplicableTo(element: T): Boolean = BranchedFoldingUtils.getFoldableExpressionKind(element) == kind override fun applyTo(element: T, editor: Editor) { diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/IfThenToDoubleBangIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/IfThenToDoubleBangIntention.kt index d52d1cfee83..10c4f0ad2ed 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/IfThenToDoubleBangIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/IfThenToDoubleBangIntention.kt @@ -16,26 +16,17 @@ package org.jetbrains.kotlin.idea.intentions.branchedTransformations.intentions -import org.jetbrains.kotlin.idea.intentions.JetSelfTargetingIntention import com.intellij.openapi.editor.Editor -import org.jetbrains.kotlin.psi.JetIfExpression -import org.jetbrains.kotlin.psi.JetBinaryExpression -import org.jetbrains.kotlin.lexer.JetTokens -import org.jetbrains.kotlin.idea.intentions.branchedTransformations.evaluatesTo -import org.jetbrains.kotlin.idea.intentions.branchedTransformations.comparesNonNullToNull -import org.jetbrains.kotlin.idea.intentions.branchedTransformations.getNonNullExpression -import org.jetbrains.kotlin.idea.intentions.branchedTransformations.replace -import org.jetbrains.kotlin.idea.intentions.branchedTransformations.isStableVariable -import org.jetbrains.kotlin.psi.JetPostfixExpression -import org.jetbrains.kotlin.idea.intentions.branchedTransformations.inlineBaseExpressionIfApplicableWithPrompt -import org.jetbrains.kotlin.idea.intentions.branchedTransformations.extractExpressionIfSingle -import org.jetbrains.kotlin.psi.JetThrowExpression import org.jetbrains.kotlin.idea.JetBundle -import org.jetbrains.kotlin.idea.intentions.branchedTransformations.isNullExpressionOrEmptyBlock -import org.jetbrains.kotlin.idea.intentions.branchedTransformations.throwsNullPointerExceptionWithNoArguments -import org.jetbrains.kotlin.idea.intentions.branchedTransformations.isStatement +import org.jetbrains.kotlin.idea.intentions.JetSelfTargetingOffsetIndependentIntention +import org.jetbrains.kotlin.idea.intentions.branchedTransformations.* +import org.jetbrains.kotlin.lexer.JetTokens +import org.jetbrains.kotlin.psi.JetBinaryExpression +import org.jetbrains.kotlin.psi.JetIfExpression +import org.jetbrains.kotlin.psi.JetPostfixExpression +import org.jetbrains.kotlin.psi.JetThrowExpression -public class IfThenToDoubleBangIntention : JetSelfTargetingIntention("if.then.to.double.bang", javaClass()) { +public class IfThenToDoubleBangIntention : JetSelfTargetingOffsetIndependentIntention("if.then.to.double.bang", javaClass()) { override fun isApplicableTo(element: JetIfExpression): Boolean { val condition = element.getCondition() diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/IfThenToElvisIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/IfThenToElvisIntention.kt index 505e94aeffa..b5f56a666a7 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/IfThenToElvisIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/IfThenToElvisIntention.kt @@ -16,25 +16,13 @@ package org.jetbrains.kotlin.idea.intentions.branchedTransformations.intentions -import org.jetbrains.kotlin.idea.intentions.JetSelfTargetingIntention import com.intellij.openapi.editor.Editor -import org.jetbrains.kotlin.psi.JetIfExpression -import org.jetbrains.kotlin.psi.JetBinaryExpression +import org.jetbrains.kotlin.idea.intentions.JetSelfTargetingOffsetIndependentIntention +import org.jetbrains.kotlin.idea.intentions.branchedTransformations.* import org.jetbrains.kotlin.lexer.JetTokens -import org.jetbrains.kotlin.idea.intentions.branchedTransformations.extractExpressionIfSingle -import org.jetbrains.kotlin.idea.intentions.branchedTransformations.evaluatesTo -import org.jetbrains.kotlin.idea.intentions.branchedTransformations.comparesNonNullToNull -import org.jetbrains.kotlin.idea.intentions.branchedTransformations.getNonNullExpression -import org.jetbrains.kotlin.idea.intentions.branchedTransformations.isNotNullExpression -import org.jetbrains.kotlin.idea.intentions.branchedTransformations.replace -import org.jetbrains.kotlin.idea.intentions.branchedTransformations.inlineLeftSideIfApplicableWithPrompt -import org.jetbrains.kotlin.idea.intentions.branchedTransformations.isStableVariable -import org.jetbrains.kotlin.idea.intentions.branchedTransformations.throwsNullPointerExceptionWithNoArguments -import org.jetbrains.kotlin.psi.JetThrowExpression -import org.jetbrains.kotlin.psi.JetPsiUtil -import org.jetbrains.kotlin.psi.JetExpression +import org.jetbrains.kotlin.psi.* -public class IfThenToElvisIntention : JetSelfTargetingIntention("if.then.to.elvis", javaClass()) { +public class IfThenToElvisIntention : JetSelfTargetingOffsetIndependentIntention("if.then.to.elvis", javaClass()) { override fun isApplicableTo(element: JetIfExpression): Boolean { val condition = element.getCondition() diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/IfThenToSafeAccessIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/IfThenToSafeAccessIntention.kt index 32a32a357eb..e8b9be75bda 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/IfThenToSafeAccessIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/IfThenToSafeAccessIntention.kt @@ -16,23 +16,13 @@ package org.jetbrains.kotlin.idea.intentions.branchedTransformations.intentions -import org.jetbrains.kotlin.idea.intentions.JetSelfTargetingIntention import com.intellij.openapi.editor.Editor -import org.jetbrains.kotlin.psi.JetExpression -import org.jetbrains.kotlin.psi.JetIfExpression -import org.jetbrains.kotlin.psi.JetBinaryExpression -import org.jetbrains.kotlin.psi.JetDotQualifiedExpression +import org.jetbrains.kotlin.idea.intentions.JetSelfTargetingOffsetIndependentIntention +import org.jetbrains.kotlin.idea.intentions.branchedTransformations.* import org.jetbrains.kotlin.lexer.JetTokens -import org.jetbrains.kotlin.idea.intentions.branchedTransformations.extractExpressionIfSingle -import org.jetbrains.kotlin.idea.intentions.branchedTransformations.comparesNonNullToNull -import org.jetbrains.kotlin.idea.intentions.branchedTransformations.getNonNullExpression -import org.jetbrains.kotlin.idea.intentions.branchedTransformations.isNullExpressionOrEmptyBlock -import org.jetbrains.kotlin.idea.intentions.branchedTransformations.replace -import org.jetbrains.kotlin.psi.JetSafeQualifiedExpression -import org.jetbrains.kotlin.idea.intentions.branchedTransformations.isStableVariable -import org.jetbrains.kotlin.idea.intentions.branchedTransformations.inlineReceiverIfApplicableWithPrompt +import org.jetbrains.kotlin.psi.* -public class IfThenToSafeAccessIntention : JetSelfTargetingIntention("if.then.to.safe.access", javaClass()) { +public class IfThenToSafeAccessIntention : JetSelfTargetingOffsetIndependentIntention("if.then.to.safe.access", javaClass()) { override fun isApplicableTo(element: JetIfExpression): Boolean { val condition = element.getCondition() 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 7920f1184eb..3ad95f35a5c 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 @@ -16,12 +16,13 @@ package org.jetbrains.kotlin.idea.intentions.branchedTransformations.intentions -import org.jetbrains.kotlin.idea.intentions.JetSelfTargetingIntention -import org.jetbrains.kotlin.psi.JetIfExpression import com.intellij.openapi.editor.Editor -import org.jetbrains.kotlin.idea.intentions.branchedTransformations.* +import org.jetbrains.kotlin.idea.intentions.JetSelfTargetingOffsetIndependentIntention +import org.jetbrains.kotlin.idea.intentions.branchedTransformations.canTransformToWhen +import org.jetbrains.kotlin.idea.intentions.branchedTransformations.transformToWhen +import org.jetbrains.kotlin.psi.JetIfExpression -public class IfToWhenIntention : JetSelfTargetingIntention("if.to.when", javaClass()) { +public class IfToWhenIntention : JetSelfTargetingOffsetIndependentIntention("if.to.when", javaClass()) { override fun isApplicableTo(element: JetIfExpression): Boolean = element.canTransformToWhen() override fun applyTo(element: JetIfExpression, editor: Editor) { diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/IntroduceWhenSubjectIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/IntroduceWhenSubjectIntention.kt index 120e9545451..10700f1b126 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/IntroduceWhenSubjectIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/IntroduceWhenSubjectIntention.kt @@ -16,12 +16,13 @@ package org.jetbrains.kotlin.idea.intentions.branchedTransformations.intentions -import org.jetbrains.kotlin.idea.intentions.JetSelfTargetingIntention -import org.jetbrains.kotlin.idea.intentions.branchedTransformations.* -import org.jetbrains.kotlin.psi.JetWhenExpression import com.intellij.openapi.editor.Editor +import org.jetbrains.kotlin.idea.intentions.JetSelfTargetingOffsetIndependentIntention +import org.jetbrains.kotlin.idea.intentions.branchedTransformations.canIntroduceSubject +import org.jetbrains.kotlin.idea.intentions.branchedTransformations.introduceSubject +import org.jetbrains.kotlin.psi.JetWhenExpression -public class IntroduceWhenSubjectIntention : JetSelfTargetingIntention("introduce.when.subject", javaClass()) { +public class IntroduceWhenSubjectIntention : JetSelfTargetingOffsetIndependentIntention("introduce.when.subject", javaClass()) { override fun isApplicableTo(element: JetWhenExpression): Boolean = element.canIntroduceSubject() override fun applyTo(element: JetWhenExpression, editor: Editor) { diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/MergeWhenIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/MergeWhenIntention.kt index e689260670a..06467b1eb68 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/MergeWhenIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/MergeWhenIntention.kt @@ -16,12 +16,13 @@ package org.jetbrains.kotlin.idea.intentions.branchedTransformations.intentions -import org.jetbrains.kotlin.idea.intentions.JetSelfTargetingIntention -import org.jetbrains.kotlin.idea.intentions.branchedTransformations.* -import org.jetbrains.kotlin.psi.JetWhenExpression import com.intellij.openapi.editor.Editor +import org.jetbrains.kotlin.idea.intentions.JetSelfTargetingOffsetIndependentIntention +import org.jetbrains.kotlin.idea.intentions.branchedTransformations.canMergeWithNext +import org.jetbrains.kotlin.idea.intentions.branchedTransformations.mergeWithNext +import org.jetbrains.kotlin.psi.JetWhenExpression -public class MergeWhenIntention : JetSelfTargetingIntention("merge.when", javaClass()) { +public class MergeWhenIntention : JetSelfTargetingOffsetIndependentIntention("merge.when", javaClass()) { override fun isApplicableTo(element: JetWhenExpression): Boolean = element.canMergeWithNext() override fun applyTo(element: JetWhenExpression, editor: Editor) { 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 d96190e1c51..bef443d2a0e 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 @@ -16,19 +16,15 @@ package org.jetbrains.kotlin.idea.intentions.branchedTransformations.intentions -import org.jetbrains.kotlin.psi.JetSafeQualifiedExpression -import org.jetbrains.kotlin.idea.intentions.JetSelfTargetingIntention import com.intellij.openapi.editor.Editor -import org.jetbrains.kotlin.psi.JetPsiFactory -import org.jetbrains.kotlin.psi.JetPsiUtil -import org.jetbrains.kotlin.psi.JetBinaryExpression +import org.jetbrains.kotlin.idea.intentions.JetSelfTargetingOffsetIndependentIntention import org.jetbrains.kotlin.idea.intentions.branchedTransformations.convertToIfNotNullExpression import org.jetbrains.kotlin.idea.intentions.branchedTransformations.introduceValueForCondition -import org.jetbrains.kotlin.psi.JetDotQualifiedExpression import org.jetbrains.kotlin.idea.intentions.branchedTransformations.isStableVariable import org.jetbrains.kotlin.idea.intentions.branchedTransformations.isStatement +import org.jetbrains.kotlin.psi.* -public class SafeAccessToIfThenIntention : JetSelfTargetingIntention("safe.access.to.if.then", javaClass()) { +public class SafeAccessToIfThenIntention : JetSelfTargetingOffsetIndependentIntention("safe.access.to.if.then", javaClass()) { override fun isApplicableTo(element: JetSafeQualifiedExpression): Boolean = true override fun applyTo(element: JetSafeQualifiedExpression, editor: Editor) { diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/UnfoldBranchedExpressionIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/UnfoldBranchedExpressionIntention.kt index f5c992b3826..4cea3b64312 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/UnfoldBranchedExpressionIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/UnfoldBranchedExpressionIntention.kt @@ -16,18 +16,15 @@ package org.jetbrains.kotlin.idea.intentions.branchedTransformations.intentions -import org.jetbrains.kotlin.psi.JetExpression -import org.jetbrains.kotlin.idea.intentions.branchedTransformations.* -import org.jetbrains.kotlin.idea.intentions.JetSelfTargetingIntention import com.intellij.openapi.editor.Editor -import org.jetbrains.kotlin.psi.JetFile -import org.jetbrains.kotlin.psi.JetBinaryExpression -import org.jetbrains.kotlin.psi.JetReturnExpression -import org.jetbrains.kotlin.psi.JetProperty +import org.jetbrains.kotlin.idea.intentions.JetSelfTargetingOffsetIndependentIntention +import org.jetbrains.kotlin.idea.intentions.branchedTransformations.BranchedUnfoldingUtils +import org.jetbrains.kotlin.idea.intentions.branchedTransformations.UnfoldableKind +import org.jetbrains.kotlin.psi.* public open class UnfoldBranchedExpressionIntention( val kind: UnfoldableKind, elementType: Class -) : JetSelfTargetingIntention(kind.getKey(), elementType) { +) : JetSelfTargetingOffsetIndependentIntention(kind.getKey(), elementType) { override fun isApplicableTo(element: T): Boolean = BranchedUnfoldingUtils.getUnfoldableExpressionKind(element) == kind override fun applyTo(element: T, editor: Editor) { diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/WhenToIfIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/WhenToIfIntention.kt index 96156c5c8b9..0cdfe007240 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/WhenToIfIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/WhenToIfIntention.kt @@ -16,12 +16,13 @@ package org.jetbrains.kotlin.idea.intentions.branchedTransformations.intentions -import org.jetbrains.kotlin.idea.intentions.JetSelfTargetingIntention -import org.jetbrains.kotlin.psi.JetWhenExpression import com.intellij.openapi.editor.Editor -import org.jetbrains.kotlin.idea.intentions.branchedTransformations.* +import org.jetbrains.kotlin.idea.intentions.JetSelfTargetingOffsetIndependentIntention +import org.jetbrains.kotlin.idea.intentions.branchedTransformations.canTransformToIf +import org.jetbrains.kotlin.idea.intentions.branchedTransformations.transformToIf +import org.jetbrains.kotlin.psi.JetWhenExpression -public class WhenToIfIntention : JetSelfTargetingIntention("when.to.if", javaClass()) { +public class WhenToIfIntention : JetSelfTargetingOffsetIndependentIntention("when.to.if", javaClass()) { override fun isApplicableTo(element: JetWhenExpression): Boolean = element.canTransformToIf() override fun applyTo(element: JetWhenExpression, editor: Editor) { diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/declarations/SplitPropertyDeclarationIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/declarations/SplitPropertyDeclarationIntention.kt index 2516cec302b..54085659b94 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/declarations/SplitPropertyDeclarationIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/declarations/SplitPropertyDeclarationIntention.kt @@ -17,10 +17,10 @@ package org.jetbrains.kotlin.idea.intentions.declarations import com.intellij.openapi.editor.Editor +import org.jetbrains.kotlin.idea.intentions.JetSelfTargetingOffsetIndependentIntention import org.jetbrains.kotlin.psi.JetProperty -import org.jetbrains.kotlin.idea.intentions.JetSelfTargetingIntention -public class SplitPropertyDeclarationIntention : JetSelfTargetingIntention("split.property.declaration", javaClass()) { +public class SplitPropertyDeclarationIntention : JetSelfTargetingOffsetIndependentIntention("split.property.declaration", javaClass()) { override fun isApplicableTo(element: JetProperty): Boolean = DeclarationUtils.checkSplitProperty(element) override fun applyTo(element: JetProperty, editor: Editor) {