From 7390e0ac663934f417a8b7db55fc0b258042c258 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Mon, 11 Jan 2016 19:45:56 +0100 Subject: [PATCH] editor is nullable in SelfTargetingIntention.applyTo() --- .../inspections/IntentionBasedInspection.kt | 11 ++++----- .../intentions/OperatorToFunctionIntention.kt | 2 +- .../idea/intentions/SelfTargetingIntention.kt | 2 +- .../kotlin/idea/quickfix/generateUtil.kt | 6 +++++ .../idea/intentions/AddBracesIntention.kt | 3 ++- .../intentions/AddForLoopIndicesIntention.kt | 5 ++-- .../intentions/AddNameToArgumentIntention.kt | 2 +- .../AddOperatorModifierIntention.kt | 2 +- .../AddValVarToConstructorParameterAction.kt | 2 +- .../AnonymousFunctionToLambdaIntention.kt | 2 +- .../ChangeVisibilityModifierIntention.kt | 2 +- .../ConvertAssertToIfWithThrowIntention.kt | 2 +- .../ConvertForEachToForLoopIntention.kt | 2 +- .../ConvertFunctionToPropertyIntention.kt | 2 +- .../ConvertIfWithThrowToAssertIntention.kt | 2 +- .../ConvertNegatedBooleanSequenceIntention.kt | 2 +- ...atedExpressionWithDemorgansLawIntention.kt | 2 +- .../ConvertParameterToReceiverIntention.kt | 2 +- ...ertPropertyInitializerToGetterIntention.kt | 2 +- .../ConvertPropertyToFunctionIntention.kt | 2 +- .../ConvertReceiverToParameterIntention.kt | 2 +- .../intentions/ConvertToBlockBodyIntention.kt | 2 +- .../ConvertToConcatenatedStringIntention.kt | 2 +- .../ConvertToExpressionBodyIntention.kt | 10 ++++---- .../ConvertToForEachFunctionCallIntention.kt | 2 +- .../ConvertToStringTemplateIntention.kt | 2 +- ...precatedCallableAddReplaceWithIntention.kt | 10 ++++---- .../idea/intentions/IfNullToElvisIntention.kt | 4 ++-- .../ImplementAbstractMemberIntention.kt | 3 ++- .../intentions/ImportAllMembersIntention.kt | 2 +- .../idea/intentions/ImportMemberIntention.kt | 2 +- .../InfixCallToOrdinaryIntention.kt | 2 +- .../InsertCurlyBracesToTemplateIntention.kt | 2 +- .../InsertExplicitTypeArgumentsIntention.kt | 2 +- .../IntroduceBackingPropertyIntention.kt | 2 +- .../intentions/InvertIfConditionIntention.kt | 10 ++++---- .../intentions/IterateExpressionIntention.kt | 5 ++-- .../MoveAssignmentToInitializerIntention.kt | 24 ++++++++++--------- .../MoveLambdaInsideParenthesesIntention.kt | 2 +- .../MoveLambdaOutsideParenthesesIntention.kt | 2 +- .../ObjectLiteralToLambdaIntention.kt | 2 +- .../ReconstructTypeInCastOrIsIntention.kt | 2 +- .../intentions/RemoveArgumentNameIntention.kt | 2 +- .../idea/intentions/RemoveBracesIntention.kt | 2 +- .../RemoveCurlyBracesFromTemplateIntention.kt | 2 +- ...veExplicitLambdaParameterTypesIntention.kt | 2 +- .../RemoveExplicitSuperQualifierIntention.kt | 2 +- .../RemoveExplicitTypeArgumentsIntention.kt | 2 +- .../intentions/RemoveExplicitTypeIntention.kt | 2 +- .../RemoveForLoopIndicesIntention.kt | 2 +- .../RemoveUnnecessaryParenthesesIntention.kt | 2 +- ...thExplicitFunctionLiteralParamIntention.kt | 3 ++- .../ReplaceWithOperatorAssignmentIntention.kt | 2 +- .../ReplaceWithOrdinaryAssignmentIntention.kt | 2 +- .../SimplifyBooleanWithConstantsIntention.kt | 2 +- ...implifyNegatedBinaryExpressionIntention.kt | 2 +- ...SpecifyExplicitLambdaSignatureIntention.kt | 2 +- .../SpecifyTypeExplicitlyIntention.kt | 2 +- .../idea/intentions/SplitIfIntention.kt | 2 +- .../SwapBinaryExpressionIntention.kt | 2 +- .../idea/intentions/ToInfixCallIntention.kt | 2 +- .../UsePropertyAccessSyntaxIntention.kt | 2 +- .../BranchedUnfoldingUtils.kt | 10 ++++---- .../branchedTransformations/IfThenUtils.kt | 10 ++++---- .../intentions/DoubleBangToIfThenIntention.kt | 4 +++- .../EliminateWhenSubjectIntention.kt | 2 +- .../intentions/ElvisToIfThenIntention.kt | 2 +- .../intentions/FlattenWhenIntention.kt | 4 ++-- .../intentions/FoldIfToAssignmentIntention.kt | 2 +- .../FoldIfToReturnAsymmetricallyIntention.kt | 2 +- .../intentions/FoldIfToReturnIntention.kt | 2 +- .../FoldWhenToAssignmentIntention.kt | 2 +- .../intentions/FoldWhenToReturnIntention.kt | 2 +- .../intentions/IfThenToDoubleBangIntention.kt | 2 +- .../intentions/IfThenToElvisIntention.kt | 4 ++-- .../intentions/IfThenToSafeAccessIntention.kt | 4 ++-- .../intentions/IfToWhenIntention.kt | 2 +- .../IntroduceWhenSubjectIntention.kt | 2 +- .../intentions/MergeWhenIntention.kt | 2 +- .../intentions/SafeAccessToIfThenIntention.kt | 2 +- .../UnfoldAssignmentToIfIntention.kt | 2 +- .../UnfoldAssignmentToWhenIntention.kt | 2 +- .../intentions/UnfoldPropertyToIfIntention.kt | 2 +- .../UnfoldPropertyToWhenIntention.kt | 2 +- .../intentions/UnfoldReturnToIfIntention.kt | 2 +- .../intentions/UnfoldReturnToWhenIntention.kt | 2 +- .../intentions/WhenToIfIntention.kt | 2 +- .../ReplaceCallWithBinaryOperatorIntention.kt | 2 +- .../ReplaceCallWithUnaryOperatorIntention.kt | 2 +- .../ReplaceContainsIntention.kt | 2 +- .../ReplaceGetOrSetIntention.kt | 2 +- .../ReplaceInvokeIntention.kt | 2 +- .../ConvertMemberToExtensionIntention.kt | 22 +++++++++-------- .../SplitPropertyDeclarationIntention.kt | 2 +- .../idea/quickfix/AddConstModifierFix.kt | 2 +- .../inline/KotlinInlineValHandler.kt | 8 +++---- .../changePackage/ChangePackageIntention.kt | 6 +++-- .../ChangePackageToMatchDirectoryIntention.kt | 2 +- ...FileToPackageMatchingDirectoryIntention.kt | 2 +- .../MoveDeclarationToSeparateFileIntention.kt | 5 ++-- .../KotlinCreateTestIntention.kt | 7 +++--- 101 files changed, 179 insertions(+), 155 deletions(-) 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 7bed3a3c1b7..69b5ae435c6 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 @@ -25,8 +25,8 @@ 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.PsiDocumentManager import com.intellij.openapi.util.TextRange +import com.intellij.psi.PsiDocumentManager import com.intellij.psi.PsiElement import com.intellij.psi.PsiElementVisitor import com.intellij.psi.PsiFile @@ -118,13 +118,12 @@ abstract class IntentionBasedInspection( assert(startElement == endElement) if (!isAvailable(project, file, startElement, endElement)) return - startElement.getOrCreateEditor()?.let { editor -> - editor.caretModel.moveToOffset(startElement.textOffset) - intention.applyTo(startElement as TElement, editor) - } + val editor = startElement.findExistingEditor() + editor?.caretModel?.moveToOffset(startElement.textOffset) + intention.applyTo(startElement as TElement, editor) } - private fun PsiElement.getOrCreateEditor(): Editor? { + private fun PsiElement.findExistingEditor(): Editor? { val file = containingFile?.virtualFile ?: return null val document = FileDocumentManager.getInstance().getDocument(file) ?: return null 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 e6aada613cd..1c1c2921d37 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 @@ -263,7 +263,7 @@ class OperatorToFunctionIntention : SelfTargetingIntention(KtExpre } } - override fun applyTo(element: KtExpression, editor: Editor) { + override fun applyTo(element: KtExpression, editor: Editor?) { convert(element) } } diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/intentions/SelfTargetingIntention.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/intentions/SelfTargetingIntention.kt index 16c17bcde3f..fad662c3982 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/intentions/SelfTargetingIntention.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/intentions/SelfTargetingIntention.kt @@ -51,7 +51,7 @@ abstract class SelfTargetingIntention( abstract fun isApplicableTo(element: TElement, caretOffset: Int): Boolean - abstract fun applyTo(element: TElement, editor: Editor) + abstract fun applyTo(element: TElement, editor: Editor?) private fun getTarget(editor: Editor, file: PsiFile): TElement? { val offset = editor.caretModel.offset diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/quickfix/generateUtil.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/quickfix/generateUtil.kt index 9d04a24eb56..f4930ec3cfb 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/quickfix/generateUtil.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/quickfix/generateUtil.kt @@ -98,6 +98,12 @@ private fun moveCaretIntoGeneratedElementDocumentUnblocked(editor: Editor, eleme return false } +fun Editor.unblockDocument() { + project?.let { + PsiDocumentManager.getInstance(it).doPostponedOperationsAndUnblockDocument(document) + } +} + fun Editor.moveCaret(offset: Int, scrollType: ScrollType = ScrollType.RELATIVE) { caretModel.moveToOffset(offset) scrollingModel.scrollToCaret(scrollType) diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/AddBracesIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/AddBracesIntention.kt index eb485dec0d9..11f7f4b7da0 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/AddBracesIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/AddBracesIntention.kt @@ -31,7 +31,8 @@ class AddBracesIntention : SelfTargetingIntention(KtExpression::cl return true } - override fun applyTo(element: KtExpression, editor: Editor) { + override fun applyTo(element: KtExpression, editor: Editor?) { + if (editor == null) throw IllegalArgumentException("This intention requires an editor") val expression = element.getTargetExpression(editor.caretModel.offset)!! if (element.nextSibling?.text == ";") { diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/AddForLoopIndicesIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/AddForLoopIndicesIntention.kt index 20b5de67507..fc36759998c 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/AddForLoopIndicesIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/AddForLoopIndicesIntention.kt @@ -24,8 +24,8 @@ import com.intellij.psi.PsiDocumentManager import org.jetbrains.kotlin.idea.analysis.analyzeInContext import org.jetbrains.kotlin.idea.caches.resolve.analyze import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade -import org.jetbrains.kotlin.idea.util.getResolutionScope import org.jetbrains.kotlin.idea.core.replaced +import org.jetbrains.kotlin.idea.util.getResolutionScope import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.psi.psiUtil.endOffset import org.jetbrains.kotlin.psi.psiUtil.startOffset @@ -56,7 +56,8 @@ class AddForLoopIndicesIntention : SelfTargetingRangeIntention( return TextRange(element.startOffset, element.body?.startOffset ?: element.endOffset) } - override fun applyTo(element: KtForExpression, editor: Editor) { + override fun applyTo(element: KtForExpression, editor: Editor?) { + if (editor == null) throw IllegalArgumentException("This intention requires an editor") val loopRange = element.loopRange!! val loopParameter = element.loopParameter!! val psiFactory = KtPsiFactory(element) diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/AddNameToArgumentIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/AddNameToArgumentIntention.kt index af99183d9e7..4e689a17ac1 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/AddNameToArgumentIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/AddNameToArgumentIntention.kt @@ -50,7 +50,7 @@ class AddNameToArgumentIntention override fun allowCaretInsideElement(element: PsiElement) = element !is KtValueArgumentList && element !is KtContainerNode - override fun applyTo(element: KtValueArgument, editor: Editor) { + override fun applyTo(element: KtValueArgument, editor: Editor?) { val name = detectNameToAdd(element)!! val newArgument = KtPsiFactory(element).createArgument(element.getArgumentExpression()!!, name, element.getSpreadElement() != null) element.replace(newArgument) diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/AddOperatorModifierIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/AddOperatorModifierIntention.kt index bd88baff2f9..dc9f9f0ca42 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/AddOperatorModifierIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/AddOperatorModifierIntention.kt @@ -32,7 +32,7 @@ class AddOperatorModifierIntention : SelfTargetingRangeIntention" } - override fun applyTo(element: KtIfExpression, editor: Editor) { + override fun applyTo(element: KtIfExpression, editor: Editor?) { val condition = element.condition ?: return val thenExpr = element.then?.unwrapBlockOrParenthesis() as KtThrowExpression diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertNegatedBooleanSequenceIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertNegatedBooleanSequenceIntention.kt index 720ef7fd617..924a81d16a3 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertNegatedBooleanSequenceIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertNegatedBooleanSequenceIntention.kt @@ -32,7 +32,7 @@ class ConvertNegatedBooleanSequenceIntention : SelfTargetingOffsetIndependentInt return splitBooleanSequence(element) != null } - override fun applyTo(element: KtBinaryExpression, editor: Editor) { + override fun applyTo(element: KtBinaryExpression, editor: Editor?) { val operatorText = when(element.operationToken) { KtTokens.ANDAND -> KtTokens.OROR.value KtTokens.OROR -> KtTokens.ANDAND.value diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertNegatedExpressionWithDemorgansLawIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertNegatedExpressionWithDemorgansLawIntention.kt index 9d6f3c36d16..dd01d364010 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertNegatedExpressionWithDemorgansLawIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertNegatedExpressionWithDemorgansLawIntention.kt @@ -38,7 +38,7 @@ class ConvertNegatedExpressionWithDemorgansLawIntention : SelfTargetingOffsetInd return splitBooleanSequence(baseExpression) != null } - override fun applyTo(element: KtPrefixExpression, editor: Editor) { + override fun applyTo(element: KtPrefixExpression, editor: Editor?) { applyTo(element) } diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertParameterToReceiverIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertParameterToReceiverIntention.kt index f047f3fa1bc..7bb69f1db4c 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertParameterToReceiverIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertParameterToReceiverIntention.kt @@ -50,7 +50,7 @@ class ConvertParameterToReceiverIntention : SelfTargetingIntention( override fun startInWriteAction() = false - override fun applyTo(element: KtParameter, editor: Editor) { + override fun applyTo(element: KtParameter, editor: Editor?) { val function = element.getStrictParentOfType() ?: return val parameterIndex = function.valueParameters.indexOf(element) val context = function.analyze() diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertPropertyInitializerToGetterIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertPropertyInitializerToGetterIntention.kt index 595b4de07a8..b349a3a8461 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertPropertyInitializerToGetterIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertPropertyInitializerToGetterIntention.kt @@ -30,7 +30,7 @@ class ConvertPropertyInitializerToGetterIntention : SelfTargetingIntention(Kt return element.delegate == null && !element.isVar && !element.isLocal } - override fun applyTo(element: KtProperty, editor: Editor) { + override fun applyTo(element: KtProperty, editor: Editor?) { val context = element.analyze() val descriptor = context[BindingContext.DECLARATION_TO_DESCRIPTOR, element] as? CallableDescriptor ?: return Converter(element.project, descriptor).run() diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertReceiverToParameterIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertReceiverToParameterIntention.kt index a837a547638..0e0d51a130d 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertReceiverToParameterIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertReceiverToParameterIntention.kt @@ -43,7 +43,7 @@ class ConvertReceiverToParameterIntention : SelfTargetingOffsetIndependentIntent override fun startInWriteAction() = false - override fun applyTo(element: KtTypeReference, editor: Editor) { + override fun applyTo(element: KtTypeReference, editor: Editor?) { val function = element.parent as? KtNamedFunction ?: return val context = function.analyze() val descriptor = context[BindingContext.DECLARATION_TO_DESCRIPTOR, function] as? FunctionDescriptor ?: return diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertToBlockBodyIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertToBlockBodyIntention.kt index 2ee6ddb89ad..87256939bbb 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertToBlockBodyIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertToBlockBodyIntention.kt @@ -47,7 +47,7 @@ class ConvertToBlockBodyIntention : SelfTargetingIntention(KtIfE return TextRange(element.startOffset, rParen.endOffset) } - override fun applyTo(element: KtIfExpression, editor: Editor) { + override fun applyTo(element: KtIfExpression, editor: Editor?) { val newElvis = applyTo(element) - editor.caretModel.moveToOffset(newElvis.right!!.textOffset) + editor?.caretModel?.moveToOffset(newElvis.right!!.textOffset) } fun applyTo(element: KtIfExpression): KtBinaryExpression { diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/ImplementAbstractMemberIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/ImplementAbstractMemberIntention.kt index ba93f0b844f..21b6a7f2d80 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/ImplementAbstractMemberIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/ImplementAbstractMemberIntention.kt @@ -200,7 +200,8 @@ abstract class ImplementAbstractMemberIntentionBase : } } - override fun applyTo(element: KtNamedDeclaration, editor: Editor) { + override fun applyTo(element: KtNamedDeclaration, editor: Editor?) { + if (editor == null) throw IllegalArgumentException("This intention requires an editor") val project = element.project val classesToProcess = project.runSynchronouslyWithProgress( diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/ImportAllMembersIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/ImportAllMembersIntention.kt index 0eb9ed52210..be0d7966fa3 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/ImportAllMembersIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/ImportAllMembersIntention.kt @@ -56,7 +56,7 @@ class ImportAllMembersIntention : SelfTargetingIntention( return element.operationReference.textRange.containsOffset(caretOffset) } - override fun applyTo(element: KtBinaryExpression, editor: Editor) { + override fun applyTo(element: KtBinaryExpression, editor: Editor?) { convert(element) } diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/InsertCurlyBracesToTemplateIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/InsertCurlyBracesToTemplateIntention.kt index 68715a9c416..c0cdc3e589a 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/InsertCurlyBracesToTemplateIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/InsertCurlyBracesToTemplateIntention.kt @@ -26,7 +26,7 @@ class InsertCurlyBracesToTemplateIntention : SelfTargetingOffsetIndependentInten override fun isApplicableTo(element: KtSimpleNameStringTemplateEntry): Boolean = true - override fun applyTo(element: KtSimpleNameStringTemplateEntry, editor: Editor) { + override fun applyTo(element: KtSimpleNameStringTemplateEntry, editor: Editor?) { val expression = element.expression ?: return element.replace(KtPsiFactory(element).createBlockStringTemplateEntry(expression)) } diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/InsertExplicitTypeArgumentsIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/InsertExplicitTypeArgumentsIntention.kt index 82cae25bf9b..a6168a35f08 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/InsertExplicitTypeArgumentsIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/InsertExplicitTypeArgumentsIntention.kt @@ -34,7 +34,7 @@ class InsertExplicitTypeArgumentsIntention : SelfTargetingRangeIntention(Kt return element.nameIdentifier?.textRange?.containsOffset(caretOffset) == true } - override fun applyTo(element: KtProperty, editor: Editor) { + override fun applyTo(element: KtProperty, editor: Editor?) { introduceBackingProperty(element) } diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/InvertIfConditionIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/InvertIfConditionIntention.kt index ed438b70bd9..8cf19900d5a 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/InvertIfConditionIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/InvertIfConditionIntention.kt @@ -17,11 +17,11 @@ package org.jetbrains.kotlin.idea.intentions import com.intellij.openapi.editor.Editor -import com.intellij.psi.PsiDocumentManager import org.jetbrains.kotlin.descriptors.FunctionDescriptor import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptor import org.jetbrains.kotlin.idea.core.replaced import org.jetbrains.kotlin.idea.quickfix.moveCaret +import org.jetbrains.kotlin.idea.quickfix.unblockDocument import org.jetbrains.kotlin.idea.util.psi.patternMatching.matches import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.psi.psiUtil.* @@ -35,7 +35,7 @@ class InvertIfConditionIntention : SelfTargetingIntention(KtIfEx return element.condition != null && element.then != null } - override fun applyTo(element: KtIfExpression, editor: Editor) { + override fun applyTo(element: KtIfExpression, editor: Editor?) { val newCondition = element.condition!!.negate() val newIf = handleSpecialCases(element, newCondition) @@ -47,8 +47,10 @@ class InvertIfConditionIntention : SelfTargetingIntention(KtIfEx simplifyIntention.applyTo(newIfCondition) } - PsiDocumentManager.getInstance(newIf.project).doPostponedOperationsAndUnblockDocument(editor.document) - editor.moveCaret(newIf.textOffset) + editor?.apply { + unblockDocument() + moveCaret(newIf.textOffset) + } } private fun handleStandardCase(ifExpression: KtIfExpression, newCondition: KtExpression): KtIfExpression { diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/IterateExpressionIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/IterateExpressionIntention.kt index 2b9925e9f52..b52f295668a 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/IterateExpressionIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/IterateExpressionIntention.kt @@ -28,9 +28,7 @@ import org.jetbrains.kotlin.idea.refactoring.introduce.introduceVariable.chooseA import org.jetbrains.kotlin.idea.refactoring.introduce.introduceVariable.suggestNamesForComponent import org.jetbrains.kotlin.idea.resolve.ideService import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers -import org.jetbrains.kotlin.idea.util.application.executeCommand import org.jetbrains.kotlin.idea.util.application.executeWriteCommand -import org.jetbrains.kotlin.idea.util.application.runWriteAction import org.jetbrains.kotlin.idea.util.getResolutionScope import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.psi.psiUtil.siblings @@ -62,7 +60,8 @@ class IterateExpressionIntention : SelfTargetingIntention(KtExpres override fun startInWriteAction() = false - override fun applyTo(element: KtExpression, editor: Editor) { + override fun applyTo(element: KtExpression, editor: Editor?) { + if (editor == null) throw IllegalArgumentException("This intention requires an editor") val elementType = data(element)!!.elementType val nameValidator = NewDeclarationNameValidator(element, element.siblings(), NewDeclarationNameValidator.Target.VARIABLES) val bindingContext = element.analyze(BodyResolveMode.PARTIAL) diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/MoveAssignmentToInitializerIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/MoveAssignmentToInitializerIntention.kt index 8201cba18d3..7b94c753010 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/MoveAssignmentToInitializerIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/MoveAssignmentToInitializerIntention.kt @@ -18,12 +18,12 @@ package org.jetbrains.kotlin.idea.intentions import com.intellij.openapi.editor.Editor import com.intellij.openapi.editor.ScrollType -import com.intellij.psi.PsiDocumentManager import com.intellij.psi.PsiElement import com.intellij.psi.PsiReferenceService import com.intellij.psi.util.PsiTreeUtil import org.jetbrains.kotlin.idea.core.canOmitDeclaredType import org.jetbrains.kotlin.idea.quickfix.moveCaret +import org.jetbrains.kotlin.idea.quickfix.unblockDocument import org.jetbrains.kotlin.lexer.KtTokens import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.psi.psiUtil.* @@ -49,7 +49,7 @@ class MoveAssignmentToInitializerIntention : } - override fun applyTo(element: KtBinaryExpression, editor: Editor) { + override fun applyTo(element: KtBinaryExpression, editor: Editor?) { val property = findTargetProperty(element) ?: return val initializer = element.right ?: return val newInitializer = property.setInitializer(initializer)!! @@ -60,16 +60,18 @@ class MoveAssignmentToInitializerIntention : initializerBlock.delete() } - PsiDocumentManager.getInstance(property.project).doPostponedOperationsAndUnblockDocument(editor.document) + editor?.apply { + unblockDocument() - val typeRef = property.typeReference - if (typeRef != null && property.canOmitDeclaredType(newInitializer, canChangeTypeToSubtype = !property.isVar)) { - val colon = property.colon!! - editor.selectionModel.setSelection(colon.startOffset, typeRef.endOffset) - editor.moveCaret(typeRef.endOffset, ScrollType.CENTER) - } - else { - editor.moveCaret(newInitializer.startOffset, ScrollType.CENTER) + val typeRef = property.typeReference + if (typeRef != null && property.canOmitDeclaredType(newInitializer, canChangeTypeToSubtype = !property.isVar)) { + val colon = property.colon!! + selectionModel.setSelection(colon.startOffset, typeRef.endOffset) + moveCaret(typeRef.endOffset, ScrollType.CENTER) + } + else { + moveCaret(newInitializer.startOffset, ScrollType.CENTER) + } } } diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/MoveLambdaInsideParenthesesIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/MoveLambdaInsideParenthesesIntention.kt index b0bcbd9185d..b32cc8b83be 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/MoveLambdaInsideParenthesesIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/MoveLambdaInsideParenthesesIntention.kt @@ -29,7 +29,7 @@ class MoveLambdaInsideParenthesesIntention : SelfTargetingIntention(KtBlockE return true } - override fun applyTo(element: KtBlockExpression, editor: Editor) { + override fun applyTo(element: KtBlockExpression, editor: Editor?) { val statement = element.statements.single() val containerNode = element.parent as KtContainerNode diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveCurlyBracesFromTemplateIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveCurlyBracesFromTemplateIntention.kt index 7c94258389b..30cb13535f1 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveCurlyBracesFromTemplateIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveCurlyBracesFromTemplateIntention.kt @@ -33,7 +33,7 @@ class RemoveCurlyBracesFromTemplateIntention : SelfTargetingOffsetIndependentInt return canPlaceAfterSimpleNameEntry(element.nextSibling) } - override fun applyTo(element: KtBlockStringTemplateEntry, editor: Editor) { + override fun applyTo(element: KtBlockStringTemplateEntry, editor: Editor?) { applyTo(element) } diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveExplicitLambdaParameterTypesIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveExplicitLambdaParameterTypesIntention.kt index d7d4b62a277..d4e3b565f43 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveExplicitLambdaParameterTypesIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveExplicitLambdaParameterTypesIntention.kt @@ -28,7 +28,7 @@ class RemoveExplicitLambdaParameterTypesIntention : SelfTargetingIntention(KtExpression::clas } } - override fun applyTo(element: KtExpression, editor: Editor) { + override fun applyTo(element: KtExpression, editor: Editor?) { val operator = when (element) { is KtIfExpression -> getFirstValidOperator(element)!! else -> element as KtOperationReferenceExpression diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/SwapBinaryExpressionIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/SwapBinaryExpressionIntention.kt index 6430b0341d8..262ffc31f6b 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/SwapBinaryExpressionIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/SwapBinaryExpressionIntention.kt @@ -53,7 +53,7 @@ class SwapBinaryExpressionIntention : SelfTargetingIntention return false } - override fun applyTo(element: KtBinaryExpression, editor: Editor) { + override fun applyTo(element: KtBinaryExpression, editor: Editor?) { // Have to use text here to preserve names like "plus" val operator = element.operationReference.text!! val convertedOperator = when (operator) { diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/ToInfixCallIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/ToInfixCallIntention.kt index c83dafb4e76..9dff3ef9bde 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/ToInfixCallIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/ToInfixCallIntention.kt @@ -48,7 +48,7 @@ class ToInfixCallIntention : SelfTargetingIntention(KtCallExpr return true } - override fun applyTo(element: KtCallExpression, editor: Editor) { + override fun applyTo(element: KtCallExpression, editor: Editor?) { val dotQualified = element.parent as KtDotQualifiedExpression val receiver = dotQualified.receiverExpression val argument = element.valueArguments.single().getArgumentExpression()!! diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/UsePropertyAccessSyntaxIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/UsePropertyAccessSyntaxIntention.kt index 84e2efc5900..2c7519f6d0a 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/UsePropertyAccessSyntaxIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/UsePropertyAccessSyntaxIntention.kt @@ -61,7 +61,7 @@ class UsePropertyAccessSyntaxIntention : SelfTargetingOffsetIndependentIntention return detectPropertyNameToUse(element) != null } - override fun applyTo(element: KtCallExpression, editor: Editor) { + override fun applyTo(element: KtCallExpression, editor: Editor?) { applyTo(element, detectPropertyNameToUse(element)!!) } diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/BranchedUnfoldingUtils.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/BranchedUnfoldingUtils.kt index 499abcee38e..2b8fc3727d7 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/BranchedUnfoldingUtils.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/BranchedUnfoldingUtils.kt @@ -17,12 +17,12 @@ package org.jetbrains.kotlin.idea.intentions.branchedTransformations import com.intellij.openapi.editor.Editor -import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.idea.core.copied +import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.psi.psiUtil.lastBlockStatementOrThis object BranchedUnfoldingUtils { - fun unfoldAssignmentToIf(assignment: KtBinaryExpression, editor: Editor) { + fun unfoldAssignmentToIf(assignment: KtBinaryExpression, editor: Editor?) { val op = assignment.operationReference.text val left = assignment.left!! val ifExpression = assignment.right as KtIfExpression @@ -38,10 +38,10 @@ object BranchedUnfoldingUtils { val resultIf = assignment.replace(newIfExpression) - editor.caretModel.moveToOffset(resultIf.textOffset) + editor?.caretModel?.moveToOffset(resultIf.textOffset) } - fun unfoldAssignmentToWhen(assignment: KtBinaryExpression, editor: Editor) { + fun unfoldAssignmentToWhen(assignment: KtBinaryExpression, editor: Editor?) { val op = assignment.operationReference.text val left = assignment.left!! val whenExpression = assignment.right as KtWhenExpression @@ -55,6 +55,6 @@ object BranchedUnfoldingUtils { val resultWhen = assignment.replace(newWhenExpression) - editor.caretModel.moveToOffset(resultWhen.textOffset) + editor?.caretModel?.moveToOffset(resultWhen.textOffset) } } diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/IfThenUtils.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/IfThenUtils.kt index a2275dac6bc..d7f246df27c 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/IfThenUtils.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/IfThenUtils.kt @@ -94,7 +94,7 @@ fun KtExpression.convertToIfStatement(condition: KtExpression, thenClause: KtExp return replaced(KtPsiFactory(this).createIf(condition, thenClause, elseClause)) } -fun KtIfExpression.introduceValueForCondition(occurrenceInThenClause: KtExpression, editor: Editor) { +fun KtIfExpression.introduceValueForCondition(occurrenceInThenClause: KtExpression, editor: Editor?) { val project = this.project val occurrenceInConditional = (this.condition as KtBinaryExpression).left!! KotlinIntroduceVariableHandler.doRefactoring(project, @@ -104,7 +104,7 @@ fun KtIfExpression.introduceValueForCondition(occurrenceInThenClause: KtExpressi null) } -fun KtNameReferenceExpression.inlineIfDeclaredLocallyAndOnlyUsedOnceWithPrompt(editor: Editor) { +fun KtNameReferenceExpression.inlineIfDeclaredLocallyAndOnlyUsedOnceWithPrompt(editor: Editor?) { val declaration = this.mainReference.resolve() as? KtProperty ?: return val enclosingElement = KtPsiUtil.getEnclosingElementForLocalDeclaration(declaration) @@ -119,15 +119,15 @@ fun KtNameReferenceExpression.inlineIfDeclaredLocallyAndOnlyUsedOnceWithPrompt(e } } -fun KtSafeQualifiedExpression.inlineReceiverIfApplicableWithPrompt(editor: Editor) { +fun KtSafeQualifiedExpression.inlineReceiverIfApplicableWithPrompt(editor: Editor?) { (this.receiverExpression as? KtNameReferenceExpression)?.inlineIfDeclaredLocallyAndOnlyUsedOnceWithPrompt(editor) } -fun KtBinaryExpression.inlineLeftSideIfApplicableWithPrompt(editor: Editor) { +fun KtBinaryExpression.inlineLeftSideIfApplicableWithPrompt(editor: Editor?) { (this.left as? KtNameReferenceExpression)?.inlineIfDeclaredLocallyAndOnlyUsedOnceWithPrompt(editor) } -fun KtPostfixExpression.inlineBaseExpressionIfApplicableWithPrompt(editor: Editor) { +fun KtPostfixExpression.inlineBaseExpressionIfApplicableWithPrompt(editor: Editor?) { (this.baseExpression as? KtNameReferenceExpression)?.inlineIfDeclaredLocallyAndOnlyUsedOnceWithPrompt(editor) } 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 37f1918836f..6ab5adff605 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 @@ -47,7 +47,9 @@ class DoubleBangToIfThenIntention : SelfTargetingRangeIntention(K return caretOffset <= lBrace.startOffset } - override fun applyTo(element: KtWhenExpression, editor: Editor) { + override fun applyTo(element: KtWhenExpression, editor: Editor?) { val subject = element.subjectExpression!! val whenExpression = KtPsiFactory(element).buildExpression { 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 31195fa0c56..0fa7921b57d 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 @@ -35,7 +35,7 @@ class ElvisToIfThenIntention : SelfTargetingRangeIntention(K null } - override fun applyTo(element: KtBinaryExpression, editor: Editor) { + override fun applyTo(element: KtBinaryExpression, editor: Editor?) { val left = KtPsiUtil.safeDeparenthesize(element.left!!) val right = KtPsiUtil.safeDeparenthesize(element.right!!) 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 b920e689aeb..b7d123c0fbd 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 @@ -42,7 +42,7 @@ class FlattenWhenIntention : SelfTargetingIntention(KtWhenExpr return elseEntry.startOffset <= caretOffset && caretOffset <= innerWhen.whenKeyword.endOffset } - override fun applyTo(element: KtWhenExpression, editor: Editor) { + override fun applyTo(element: KtWhenExpression, editor: Editor?) { val subjectExpression = element.subjectExpression val nestedWhen = element.elseExpression as KtWhenExpression @@ -72,6 +72,6 @@ class FlattenWhenIntention : SelfTargetingIntention(KtWhenExpr val newWhen = element.replaced(whenExpression) val firstNewEntry = newWhen.entries[outerEntries.size - 1] - editor.moveCaret(firstNewEntry.textOffset) + editor?.moveCaret(firstNewEntry.textOffset) } } diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/FoldIfToAssignmentIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/FoldIfToAssignmentIntention.kt index e1bc0593f40..34e698ef56c 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/FoldIfToAssignmentIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/FoldIfToAssignmentIntention.kt @@ -32,7 +32,7 @@ class FoldIfToAssignmentIntention : SelfTargetingRangeIntention( return element.ifKeyword.textRange } - override fun applyTo(element: KtIfExpression, editor: Editor) { + override fun applyTo(element: KtIfExpression, editor: Editor?) { var thenAssignment = BranchedFoldingUtils.getFoldableBranchedAssignment(element.then!!)!! val elseAssignment = BranchedFoldingUtils.getFoldableBranchedAssignment(element.`else`!!)!! diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/FoldIfToReturnAsymmetricallyIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/FoldIfToReturnAsymmetricallyIntention.kt index 1a928e94350..e0cdf96f52a 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/FoldIfToReturnAsymmetricallyIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/FoldIfToReturnAsymmetricallyIntention.kt @@ -33,7 +33,7 @@ class FoldIfToReturnAsymmetricallyIntention : SelfTargetingRangeIntention(KtIf return element.ifKeyword.textRange } - override fun applyTo(element: KtIfExpression, editor: Editor) { + override fun applyTo(element: KtIfExpression, editor: Editor?) { val thenReturn = BranchedFoldingUtils.getFoldableBranchedReturn(element.then!!)!! val elseReturn = BranchedFoldingUtils.getFoldableBranchedReturn(element.`else`!!)!! diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/FoldWhenToAssignmentIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/FoldWhenToAssignmentIntention.kt index 5ed4d4813e6..dd8af1f1f7f 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/FoldWhenToAssignmentIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/FoldWhenToAssignmentIntention.kt @@ -47,7 +47,7 @@ class FoldWhenToAssignmentIntention : SelfTargetingRangeIntention( return element.whenKeyword.textRange } - override fun applyTo(element: KtWhenExpression, editor: Editor) { + override fun applyTo(element: KtWhenExpression, editor: Editor?) { assert(!element.entries.isEmpty()) val newReturnExpression = KtPsiFactory(element).createExpressionByPattern("return $0", element) as KtReturnExpression 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 534f49d118c..b23122ab20d 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 @@ -66,7 +66,7 @@ class IfThenToDoubleBangIntention : SelfTargetingRangeIntention( return TextRange(element.startOffset, rParen.endOffset) } - override fun applyTo(element: KtIfExpression, editor: Editor) { + override fun applyTo(element: KtIfExpression, editor: Editor?) { val condition = element.condition as KtBinaryExpression val expression = condition.expressionComparedToNull()!! val result = element.replace(KtPsiFactory(element).createExpressionByPattern("$0!!", expression)) as KtPostfixExpression 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 5debf9bb893..9d07951ec31 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 @@ -18,12 +18,12 @@ package org.jetbrains.kotlin.idea.intentions.branchedTransformations.intentions import com.intellij.openapi.editor.Editor import org.jetbrains.kotlin.KtNodeTypes +import org.jetbrains.kotlin.idea.core.replaced import org.jetbrains.kotlin.idea.inspections.IntentionBasedInspection import org.jetbrains.kotlin.idea.intentions.SelfTargetingOffsetIndependentIntention import org.jetbrains.kotlin.idea.intentions.branchedTransformations.* import org.jetbrains.kotlin.lexer.KtTokens import org.jetbrains.kotlin.psi.* -import org.jetbrains.kotlin.idea.core.replaced class IfThenToElvisInspection : IntentionBasedInspection(IfThenToElvisIntention()) @@ -56,7 +56,7 @@ class IfThenToElvisIntention : SelfTargetingOffsetIndependentIntention(IfThenToSafeAccessIntention()) @@ -50,7 +50,7 @@ class IfThenToSafeAccessIntention : SelfTargetingOffsetIndependentIntention(KtIfExpres return element.ifKeyword.textRange } - override fun applyTo(element: KtIfExpression, editor: Editor) { + override fun applyTo(element: KtIfExpression, editor: Editor?) { var whenExpression = KtPsiFactory(element).buildExpression { appendFixedText("when {\n") 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 6076cb3ff3d..7baaa8c31a8 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 @@ -33,7 +33,7 @@ class IntroduceWhenSubjectIntention : SelfTargetingRangeIntention(KtWhenE ?.mapNotNull { it.name } ?.toSet() ?: emptySet() - override fun applyTo(element: KtWhenExpression, editor: Editor) { + override fun applyTo(element: KtWhenExpression, editor: Editor?) { val nextWhen = PsiTreeUtil.skipSiblingsForward(element, PsiWhiteSpace::class.java) as KtWhenExpression for ((entry1, entry2) in element.entries.zip(nextWhen.entries)) { entry1.expression.mergeWith(entry2.expression) 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 600c2530d4e..dbcb9067a3b 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 @@ -33,7 +33,7 @@ class SafeAccessToIfThenIntention : SelfTargetingRangeIntention(KtPr return TextRange(element.startOffset, initializer.ifKeyword.endOffset) } - override fun applyTo(element: KtProperty, editor: Editor) { + override fun applyTo(element: KtProperty, editor: Editor?) { val assignment = splitPropertyDeclaration(element) BranchedUnfoldingUtils.unfoldAssignmentToIf(assignment, editor) } diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/UnfoldPropertyToWhenIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/UnfoldPropertyToWhenIntention.kt index 58382e1414a..e3ace79253e 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/UnfoldPropertyToWhenIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/UnfoldPropertyToWhenIntention.kt @@ -37,7 +37,7 @@ class UnfoldPropertyToWhenIntention : SelfTargetingRangeIntention(Kt return TextRange(element.startOffset, initializer.whenKeyword.endOffset) } - override fun applyTo(element: KtProperty, editor: Editor) { + override fun applyTo(element: KtProperty, editor: Editor?) { val assignment = splitPropertyDeclaration(element) BranchedUnfoldingUtils.unfoldAssignmentToWhen(assignment, editor) } diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/UnfoldReturnToIfIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/UnfoldReturnToIfIntention.kt index b934b8c18e2..11a87aa74db 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/UnfoldReturnToIfIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/UnfoldReturnToIfIntention.kt @@ -35,7 +35,7 @@ class UnfoldReturnToIfIntention : SelfTargetingRangeIntention(KtWhenEx return element.whenKeyword.textRange } - override fun applyTo(element: KtWhenExpression, editor: Editor) { + override fun applyTo(element: KtWhenExpression, editor: Editor?) { val factory = KtPsiFactory(element) val ifExpression = factory.buildExpression { val entries = element.entries diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/conventionNameCalls/ReplaceCallWithBinaryOperatorIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/conventionNameCalls/ReplaceCallWithBinaryOperatorIntention.kt index 64d194d5068..541307b7fc8 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/conventionNameCalls/ReplaceCallWithBinaryOperatorIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/conventionNameCalls/ReplaceCallWithBinaryOperatorIntention.kt @@ -45,7 +45,7 @@ class ReplaceCallWithBinaryOperatorIntention : SelfTargetingRangeIntention(KtProperty::class.java, "Add 'const' modifier") { - override fun applyTo(element: KtProperty, editor: Editor) { + override fun applyTo(element: KtProperty, editor: Editor?) { AddConstModifierFix.addConstModifier(element) } diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/inline/KotlinInlineValHandler.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/inline/KotlinInlineValHandler.kt index 4337ffc5e59..27c7d005ac8 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/inline/KotlinInlineValHandler.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/inline/KotlinInlineValHandler.kt @@ -41,10 +41,10 @@ import org.jetbrains.kotlin.idea.KotlinLanguage import org.jetbrains.kotlin.idea.caches.resolve.analyze import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade import org.jetbrains.kotlin.idea.codeInsight.shorten.performDelayedShortening +import org.jetbrains.kotlin.idea.core.replaced import org.jetbrains.kotlin.idea.refactoring.addTypeArgumentsIfNeeded import org.jetbrains.kotlin.idea.refactoring.checkConflictsInteractively import org.jetbrains.kotlin.idea.refactoring.getQualifiedTypeArgumentList -import org.jetbrains.kotlin.idea.core.replaced import org.jetbrains.kotlin.idea.refactoring.move.PackageNameInfo import org.jetbrains.kotlin.idea.refactoring.move.lazilyProcessInternalReferencesToUpdateOnPackageNameChange import org.jetbrains.kotlin.idea.refactoring.move.postProcessMoveUsages @@ -110,7 +110,7 @@ class KotlinInlineValHandler : InlineActionHandler() { return expression.replaced(replacement).singletonList() } - override fun inlineElement(project: Project, editor: Editor, element: PsiElement) { + override fun inlineElement(project: Project, editor: Editor?, element: PsiElement) { val declaration = element as KtProperty val file = declaration.getContainingKtFile() val name = declaration.name ?: return @@ -243,13 +243,13 @@ class KotlinInlineValHandler : InlineActionHandler() { } } - private fun reportAmbiguousAssignment(project: Project, editor: Editor, name: String, assignments: Set) { + private fun reportAmbiguousAssignment(project: Project, editor: Editor?, name: String, assignments: Set) { val key = if (assignments.isEmpty()) "variable.has.no.initializer" else "variable.has.no.dominating.definition" val message = RefactoringBundle.getCannotRefactorMessage(RefactoringBundle.message(key, name)) showErrorHint(project, editor, message) } - private fun showErrorHint(project: Project, editor: Editor, message: String) { + private fun showErrorHint(project: Project, editor: Editor?, message: String) { CommonRefactoringUtil.showErrorHint(project, editor, message, RefactoringBundle.message("inline.variable.title"), HelpID.INLINE_VARIABLE) } diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/move/changePackage/ChangePackageIntention.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/move/changePackage/ChangePackageIntention.kt index b18ed5bd45c..8afe56ccafc 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/move/changePackage/ChangePackageIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/move/changePackage/ChangePackageIntention.kt @@ -24,8 +24,8 @@ import com.intellij.openapi.editor.Editor import com.intellij.openapi.util.TextRange import com.intellij.psi.PsiDocumentManager import org.jetbrains.kotlin.idea.codeInsight.CodeInsightUtils -import org.jetbrains.kotlin.idea.refactoring.hasIdentifiersOnly import org.jetbrains.kotlin.idea.intentions.SelfTargetingOffsetIndependentIntention +import org.jetbrains.kotlin.idea.refactoring.hasIdentifiersOnly import org.jetbrains.kotlin.idea.util.application.executeWriteCommand import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.name.FqNameUnsafe @@ -38,11 +38,13 @@ class ChangePackageIntention: SelfTargetingOffsetIndependentIntention element.toLightClass() else -> element.getContainingKtFile().findFacadeClass()