From 32290ec1d325f65849bf00054e0ce20e9a0c8198 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Tue, 18 Oct 2016 19:32:14 +0200 Subject: [PATCH] add missing prepareForWrite() calls --- .../kotlin/idea/inspections/IntentionBasedInspection.kt | 2 ++ .../kotlin/idea/intentions/SelfTargetingIntention.kt | 2 ++ .../kotlin/idea/kdoc/KDocMissingDocumentationInspection.kt | 2 ++ .../kotlin/idea/quickfix/KotlinSuppressIntentionAction.kt | 3 +++ .../core/overrideImplement/OverrideImplementMembersHandler.kt | 3 +++ .../org/jetbrains/kotlin/idea/inspections/AddModifierFix.kt | 2 ++ .../kotlin/idea/inspections/AddVarianceModifierInspection.kt | 2 ++ .../kotlin/idea/inspections/CanBeParameterInspection.kt | 2 ++ .../inspections/CanBePrimaryConstructorPropertyInspection.kt | 3 +++ .../inspections/ConflictingExtensionPropertyInspection.kt | 2 ++ .../kotlin/idea/inspections/EqualsOrHashCodeInspection.kt | 4 ++++ .../kotlin/idea/inspections/ProtectedInFinalInspection.kt | 3 +++ .../kotlin/idea/inspections/RedundantSemicolonInspection.kt | 2 ++ .../jetbrains/kotlin/idea/inspections/RemoveModifierFix.kt | 2 ++ .../inspections/RemoveToStringInStringTemplateInspection.kt | 3 +++ .../idea/inspections/UnusedReceiverParameterInspection.kt | 3 +++ .../kotlin/idea/intentions/CreateKotlinSubClassIntention.kt | 2 ++ .../idea/quickfix/AddOverrideToEqualsHashCodeToStringFix.kt | 2 ++ .../org/jetbrains/kotlin/idea/quickfix/ExclExclCallFixes.kt | 2 ++ .../kotlin/idea/quickfix/SpecifyTypeExplicitlyFix.kt | 3 +++ .../kotlin/idea/refactoring/kotlinRefactoringUtil.kt | 2 +- 21 files changed, 50 insertions(+), 1 deletion(-) 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 d7c09014624..414ca1f681a 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,6 +16,7 @@ package org.jetbrains.kotlin.idea.inspections +import com.intellij.codeInsight.FileModificationService import com.intellij.codeInsight.intention.HighPriorityAction import com.intellij.codeInsight.intention.IntentionAction import com.intellij.codeInsight.intention.LowPriorityAction @@ -167,6 +168,7 @@ abstract class IntentionBasedInspection( override fun invoke(project: Project, file: PsiFile, startElement: PsiElement, endElement: PsiElement) { assert(startElement == endElement) if (!isAvailable(project, file, startElement, endElement)) return + if (!FileModificationService.getInstance().prepareFileForWrite(file)) return val editor = startElement.findExistingEditor() editor?.caretModel?.moveToOffset(startElement.textOffset) 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 177e0ab28be..09656ac7072 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 @@ -16,6 +16,7 @@ package org.jetbrains.kotlin.idea.intentions +import com.intellij.codeInsight.FileModificationService import com.intellij.codeInsight.daemon.HighlightDisplayKey import com.intellij.codeInsight.intention.IntentionAction import com.intellij.codeInspection.LocalInspectionEP @@ -104,6 +105,7 @@ abstract class SelfTargetingIntention( final override fun invoke(project: Project, editor: Editor, file: PsiFile): Unit { PsiDocumentManager.getInstance(project).commitAllDocuments() val target = getTarget(editor, file) ?: return + if (!FileModificationService.getInstance().preparePsiElementForWrite(target)) return applyTo(target, editor) } diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/kdoc/KDocMissingDocumentationInspection.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/kdoc/KDocMissingDocumentationInspection.kt index 2b710f42551..9d2399fdd59 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/kdoc/KDocMissingDocumentationInspection.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/kdoc/KDocMissingDocumentationInspection.kt @@ -16,6 +16,7 @@ package org.jetbrains.kotlin.idea.kdoc +import com.intellij.codeInsight.FileModificationService import com.intellij.codeInspection.LocalQuickFix import com.intellij.codeInspection.ProblemDescriptor import com.intellij.codeInspection.ProblemsHolder @@ -69,6 +70,7 @@ class KDocMissingDocumentationInspection(): AbstractKotlinInspection() { override fun getFamilyName(): String = name override fun applyFix(project: Project, descriptor: ProblemDescriptor) { + if (!FileModificationService.getInstance().preparePsiElementForWrite(descriptor.psiElement)) return val declaration = descriptor.psiElement.getParentOfType(true) ?: throw IllegalStateException("Can't find declaration") declaration.addBefore(KDocElementFactory(project).createKDocFromText("/** */"), declaration.firstChild) diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/quickfix/KotlinSuppressIntentionAction.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/quickfix/KotlinSuppressIntentionAction.kt index 2495218acfe..78a6b4126bd 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/quickfix/KotlinSuppressIntentionAction.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/quickfix/KotlinSuppressIntentionAction.kt @@ -16,6 +16,7 @@ package org.jetbrains.kotlin.idea.quickfix +import com.intellij.codeInsight.FileModificationService import com.intellij.codeInspection.SuppressIntentionAction import com.intellij.openapi.editor.Editor import com.intellij.openapi.project.Project @@ -47,6 +48,8 @@ class KotlinSuppressIntentionAction private constructor( override fun isAvailable(project: Project, editor: Editor?, element: PsiElement) = element.isValid override fun invoke(project: Project, editor: Editor?, element: PsiElement) { + if (!FileModificationService.getInstance().preparePsiElementForWrite(element)) return + val id = "\"$suppressKey\"" when (suppressAt) { is KtModifierListOwner -> diff --git a/idea/idea-core/src/org/jetbrains/kotlin/idea/core/overrideImplement/OverrideImplementMembersHandler.kt b/idea/idea-core/src/org/jetbrains/kotlin/idea/core/overrideImplement/OverrideImplementMembersHandler.kt index 5bab68cc526..e9a2eaa35dd 100644 --- a/idea/idea-core/src/org/jetbrains/kotlin/idea/core/overrideImplement/OverrideImplementMembersHandler.kt +++ b/idea/idea-core/src/org/jetbrains/kotlin/idea/core/overrideImplement/OverrideImplementMembersHandler.kt @@ -16,6 +16,7 @@ package org.jetbrains.kotlin.idea.core.overrideImplement +import com.intellij.codeInsight.FileModificationService import com.intellij.codeInsight.hint.HintManager import com.intellij.ide.util.MemberChooser import com.intellij.lang.LanguageCodeInsightActionHandler @@ -66,6 +67,8 @@ abstract class OverrideImplementMembersHandler : LanguageCodeInsightActionHandle val elementAtCaret = file.findElementAt(editor.caretModel.offset) val classOrObject = elementAtCaret?.getNonStrictParentOfType() ?: return + if (!FileModificationService.getInstance().prepareFileForWrite(file)) return + val members = collectMembersToGenerate(classOrObject) if (members.isEmpty() && !implementAll) { HintManager.getInstance().showErrorHint(editor, getNoMembersFoundHint()) diff --git a/idea/src/org/jetbrains/kotlin/idea/inspections/AddModifierFix.kt b/idea/src/org/jetbrains/kotlin/idea/inspections/AddModifierFix.kt index 3224d76fdd0..1567131e628 100644 --- a/idea/src/org/jetbrains/kotlin/idea/inspections/AddModifierFix.kt +++ b/idea/src/org/jetbrains/kotlin/idea/inspections/AddModifierFix.kt @@ -16,6 +16,7 @@ package org.jetbrains.kotlin.idea.inspections +import com.intellij.codeInsight.FileModificationService import com.intellij.codeInspection.LocalQuickFix import com.intellij.codeInspection.ProblemDescriptor import com.intellij.openapi.project.Project @@ -32,6 +33,7 @@ open class AddModifierFix(val modifierListOwner: KtModifierListOwner, override fun getFamilyName() = text final override fun applyFix(project: Project, descriptor: ProblemDescriptor) { + if (!FileModificationService.getInstance().preparePsiElementForWrite(descriptor.psiElement)) return addModifier(modifierListOwner, modifier) } } \ No newline at end of file diff --git a/idea/src/org/jetbrains/kotlin/idea/inspections/AddVarianceModifierInspection.kt b/idea/src/org/jetbrains/kotlin/idea/inspections/AddVarianceModifierInspection.kt index 557ee318bd0..54ab839938f 100644 --- a/idea/src/org/jetbrains/kotlin/idea/inspections/AddVarianceModifierInspection.kt +++ b/idea/src/org/jetbrains/kotlin/idea/inspections/AddVarianceModifierInspection.kt @@ -16,6 +16,7 @@ package org.jetbrains.kotlin.idea.inspections +import com.intellij.codeInsight.FileModificationService import com.intellij.codeInspection.* import com.intellij.openapi.project.Project import com.intellij.psi.PsiElementVisitor @@ -77,6 +78,7 @@ class AddVarianceModifierInspection : AbstractKotlinInspection() { override fun getFamilyName() = "Add variance" override fun applyFix(project: Project, descriptor: ProblemDescriptor) { + if (!FileModificationService.getInstance().preparePsiElementForWrite(descriptor.psiElement)) return val typeParameter = descriptor.psiElement as? KtTypeParameter ?: throw AssertionError("Add variance fix is used on ${descriptor.psiElement.text}") addModifier(typeParameter, if (variance == Variance.IN_VARIANCE) KtTokens.IN_KEYWORD else KtTokens.OUT_KEYWORD) diff --git a/idea/src/org/jetbrains/kotlin/idea/inspections/CanBeParameterInspection.kt b/idea/src/org/jetbrains/kotlin/idea/inspections/CanBeParameterInspection.kt index 091877fbd60..2d212cd321a 100644 --- a/idea/src/org/jetbrains/kotlin/idea/inspections/CanBeParameterInspection.kt +++ b/idea/src/org/jetbrains/kotlin/idea/inspections/CanBeParameterInspection.kt @@ -16,6 +16,7 @@ package org.jetbrains.kotlin.idea.inspections +import com.intellij.codeInsight.FileModificationService import com.intellij.codeInspection.LocalQuickFix import com.intellij.codeInspection.ProblemDescriptor import com.intellij.codeInspection.ProblemHighlightType @@ -124,6 +125,7 @@ class CanBeParameterInspection : AbstractKotlinInspection() { override fun getFamilyName() = fix.familyName override fun applyFix(project: Project, descriptor: ProblemDescriptor) { + if (!FileModificationService.getInstance().preparePsiElementForWrite(descriptor.psiElement)) return parameter.valOrVarKeyword?.delete() // Delete visibility / open / final / lateinit, if any // Retain annotations / vararg diff --git a/idea/src/org/jetbrains/kotlin/idea/inspections/CanBePrimaryConstructorPropertyInspection.kt b/idea/src/org/jetbrains/kotlin/idea/inspections/CanBePrimaryConstructorPropertyInspection.kt index aa7bc73d703..a89178e3247 100644 --- a/idea/src/org/jetbrains/kotlin/idea/inspections/CanBePrimaryConstructorPropertyInspection.kt +++ b/idea/src/org/jetbrains/kotlin/idea/inspections/CanBePrimaryConstructorPropertyInspection.kt @@ -16,6 +16,7 @@ package org.jetbrains.kotlin.idea.inspections +import com.intellij.codeInsight.FileModificationService import com.intellij.codeInspection.LocalQuickFix import com.intellij.codeInspection.ProblemDescriptor import com.intellij.codeInspection.ProblemHighlightType @@ -78,6 +79,8 @@ class CanBePrimaryConstructorPropertyInspection : AbstractKotlinInspection() { override fun getFamilyName() = "Move to constructor" override fun applyFix(project: Project, descriptor: ProblemDescriptor) { + if (!FileModificationService.getInstance().preparePsiElementForWrite(descriptor.psiElement)) return + val commentSaver = CommentSaver(original) val isVar = original.isVar val modifiers = original.modifierList?.text diff --git a/idea/src/org/jetbrains/kotlin/idea/inspections/ConflictingExtensionPropertyInspection.kt b/idea/src/org/jetbrains/kotlin/idea/inspections/ConflictingExtensionPropertyInspection.kt index 9015d994530..32ecc1d5d43 100644 --- a/idea/src/org/jetbrains/kotlin/idea/inspections/ConflictingExtensionPropertyInspection.kt +++ b/idea/src/org/jetbrains/kotlin/idea/inspections/ConflictingExtensionPropertyInspection.kt @@ -16,6 +16,7 @@ package org.jetbrains.kotlin.idea.inspections +import com.intellij.codeInsight.FileModificationService import com.intellij.codeInsight.intention.LowPriorityAction import com.intellij.codeInspection.* import com.intellij.openapi.diagnostic.Logger @@ -204,6 +205,7 @@ class ConflictingExtensionPropertyInspection : AbstractKotlinInspection(), Clean UIUtil.invokeLaterIfNeeded { project.executeWriteCommand(text) { importsToDelete.forEach { import -> + if (!FileModificationService.getInstance().preparePsiElementForWrite(import)) return@forEach try { import.delete() } diff --git a/idea/src/org/jetbrains/kotlin/idea/inspections/EqualsOrHashCodeInspection.kt b/idea/src/org/jetbrains/kotlin/idea/inspections/EqualsOrHashCodeInspection.kt index 5cfea153913..bb5a9f08000 100644 --- a/idea/src/org/jetbrains/kotlin/idea/inspections/EqualsOrHashCodeInspection.kt +++ b/idea/src/org/jetbrains/kotlin/idea/inspections/EqualsOrHashCodeInspection.kt @@ -16,6 +16,8 @@ package org.jetbrains.kotlin.idea.inspections +import com.intellij.codeInsight.CodeInsightUtilBase +import com.intellij.codeInsight.FileModificationService import com.intellij.codeInspection.InspectionsBundle import com.intellij.codeInspection.LocalQuickFix import com.intellij.codeInspection.ProblemDescriptor @@ -42,6 +44,7 @@ object DeleteEqualsAndHashCodeFix : LocalQuickFix { override fun getFamilyName() = name override fun applyFix(project: Project, descriptor: ProblemDescriptor) { + if (!FileModificationService.getInstance().preparePsiElementForWrite(descriptor.psiElement)) return val objectDeclaration = descriptor.psiElement.getStrictParentOfType() ?: return val classDescriptor = objectDeclaration.resolveToDescriptorIfAny() as? ClassDescriptor ?: return classDescriptor.findDeclaredEquals(false)?.source?.getPsi()?.delete() @@ -61,6 +64,7 @@ sealed class GenerateEqualsOrHashCodeFix : LocalQuickFix { override fun getFamilyName() = name override fun applyFix(project: Project, descriptor: ProblemDescriptor) { + if (!FileModificationService.getInstance().preparePsiElementForWrite(descriptor.psiElement)) return KotlinGenerateEqualsAndHashcodeAction().doInvoke(project, null, descriptor.psiElement.parent as KtClass) } } diff --git a/idea/src/org/jetbrains/kotlin/idea/inspections/ProtectedInFinalInspection.kt b/idea/src/org/jetbrains/kotlin/idea/inspections/ProtectedInFinalInspection.kt index 2d608780802..68dc57440b0 100644 --- a/idea/src/org/jetbrains/kotlin/idea/inspections/ProtectedInFinalInspection.kt +++ b/idea/src/org/jetbrains/kotlin/idea/inspections/ProtectedInFinalInspection.kt @@ -16,6 +16,7 @@ package org.jetbrains.kotlin.idea.inspections +import com.intellij.codeInsight.FileModificationService import com.intellij.codeInspection.* import com.intellij.openapi.project.Project import com.intellij.psi.PsiElementVisitor @@ -56,6 +57,7 @@ class ProtectedInFinalInspection : AbstractKotlinInspection() { override fun getFamilyName(): String = name override fun applyFix(project: Project, descriptor: ProblemDescriptor) { + if (!FileModificationService.getInstance().preparePsiElementForWrite(descriptor.psiElement)) return val modifierListOwner = descriptor.psiElement.getParentOfType(true) ?: throw IllegalStateException("Can't find modifier list owner for modifier") addModifier(modifierListOwner, KtTokens.PRIVATE_KEYWORD) @@ -68,6 +70,7 @@ class ProtectedInFinalInspection : AbstractKotlinInspection() { override fun getFamilyName(): String = name override fun applyFix(project: Project, descriptor: ProblemDescriptor) { + if (!FileModificationService.getInstance().preparePsiElementForWrite(descriptor.psiElement)) return val modifierListOwner = descriptor.psiElement.getParentOfType(true) ?: throw IllegalStateException("Can't find modifier list owner for modifier") val parentClass = modifierListOwner.getParentOfType(true) ?: return diff --git a/idea/src/org/jetbrains/kotlin/idea/inspections/RedundantSemicolonInspection.kt b/idea/src/org/jetbrains/kotlin/idea/inspections/RedundantSemicolonInspection.kt index 9c57d106dd9..d751d12e4a1 100644 --- a/idea/src/org/jetbrains/kotlin/idea/inspections/RedundantSemicolonInspection.kt +++ b/idea/src/org/jetbrains/kotlin/idea/inspections/RedundantSemicolonInspection.kt @@ -16,6 +16,7 @@ package org.jetbrains.kotlin.idea.inspections +import com.intellij.codeInsight.FileModificationService import com.intellij.codeInspection.* import com.intellij.openapi.project.Project import com.intellij.psi.PsiComment @@ -63,6 +64,7 @@ class RedundantSemicolonInspection : AbstractKotlinInspection(), CleanupLocalIns override fun getFamilyName() = name override fun applyFix(project: Project, descriptor: ProblemDescriptor) { + if (!FileModificationService.getInstance().preparePsiElementForWrite(descriptor.psiElement)) return descriptor.psiElement.delete() } } diff --git a/idea/src/org/jetbrains/kotlin/idea/inspections/RemoveModifierFix.kt b/idea/src/org/jetbrains/kotlin/idea/inspections/RemoveModifierFix.kt index 7d26da5d011..28a2e335dc8 100644 --- a/idea/src/org/jetbrains/kotlin/idea/inspections/RemoveModifierFix.kt +++ b/idea/src/org/jetbrains/kotlin/idea/inspections/RemoveModifierFix.kt @@ -16,6 +16,7 @@ package org.jetbrains.kotlin.idea.inspections +import com.intellij.codeInsight.FileModificationService import com.intellij.codeInspection.LocalQuickFix import com.intellij.codeInspection.ProblemDescriptor import com.intellij.openapi.project.Project @@ -33,6 +34,7 @@ class RemoveModifierFix(val text: String) : LocalQuickFix { val modifierKeyword = descriptor.psiElement.node.elementType as KtModifierKeywordToken val modifierListOwner = descriptor.psiElement.getParentOfType(true) ?: throw IllegalStateException("Can't find modifier list owner for modifier") + if (!FileModificationService.getInstance().preparePsiElementForWrite(modifierListOwner)) return removeModifier(modifierListOwner, modifierKeyword) } } diff --git a/idea/src/org/jetbrains/kotlin/idea/inspections/RemoveToStringInStringTemplateInspection.kt b/idea/src/org/jetbrains/kotlin/idea/inspections/RemoveToStringInStringTemplateInspection.kt index 467331b3bc5..e402022ba5d 100644 --- a/idea/src/org/jetbrains/kotlin/idea/inspections/RemoveToStringInStringTemplateInspection.kt +++ b/idea/src/org/jetbrains/kotlin/idea/inspections/RemoveToStringInStringTemplateInspection.kt @@ -16,6 +16,7 @@ package org.jetbrains.kotlin.idea.inspections +import com.intellij.codeInsight.FileModificationService import com.intellij.codeInspection.* import com.intellij.openapi.project.Project import org.jetbrains.kotlin.descriptors.CallableDescriptor @@ -56,6 +57,8 @@ class RemoveToStringFix: LocalQuickFix { override fun applyFix(project: Project, descriptor: ProblemDescriptor) { val element = descriptor.psiElement.parent as? KtDotQualifiedExpression ?: return + if (!FileModificationService.getInstance().preparePsiElementForWrite(element)) return + val receiverExpression = element.receiverExpression if (receiverExpression is KtNameReferenceExpression) { val templateEntry = receiverExpression.parent.parent diff --git a/idea/src/org/jetbrains/kotlin/idea/inspections/UnusedReceiverParameterInspection.kt b/idea/src/org/jetbrains/kotlin/idea/inspections/UnusedReceiverParameterInspection.kt index df32d5063d6..904f1aaa90b 100644 --- a/idea/src/org/jetbrains/kotlin/idea/inspections/UnusedReceiverParameterInspection.kt +++ b/idea/src/org/jetbrains/kotlin/idea/inspections/UnusedReceiverParameterInspection.kt @@ -16,6 +16,7 @@ package org.jetbrains.kotlin.idea.inspections +import com.intellij.codeInsight.FileModificationService import com.intellij.codeInspection.* import com.intellij.openapi.project.Project import com.intellij.psi.PsiElement @@ -116,6 +117,8 @@ class UnusedReceiverParameterInspection : AbstractKotlinInspection() { override fun applyFix(project: Project, descriptor: ProblemDescriptor) { val element = descriptor.psiElement + if (!FileModificationService.getInstance().preparePsiElementForWrite(element)) return + val function = element.parent as? KtCallableDeclaration ?: return val callableDescriptor = function.analyze()[BindingContext.DECLARATION_TO_DESCRIPTOR, function] as? CallableDescriptor ?: return runChangeSignature(project, callableDescriptor, configureChangeSignature(), element, name) diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/CreateKotlinSubClassIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/CreateKotlinSubClassIntention.kt index acef3c2cc83..84df2588cd1 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/CreateKotlinSubClassIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/CreateKotlinSubClassIntention.kt @@ -17,6 +17,7 @@ package org.jetbrains.kotlin.idea.intentions import com.intellij.codeInsight.CodeInsightUtil +import com.intellij.codeInsight.FileModificationService import com.intellij.codeInsight.daemon.impl.quickfix.CreateClassKind import com.intellij.codeInsight.intention.impl.CreateClassDialog import com.intellij.openapi.application.ApplicationManager @@ -79,6 +80,7 @@ class CreateKotlinSubClassIntention : SelfTargetingRangeIntention(KtCla override fun applyTo(element: KtClass, editor: Editor?) { if (editor == null) throw IllegalArgumentException("This intention requires an editor") + val name = element.name ?: throw IllegalStateException("This intention should not be applied to anonymous classes") val baseClass = element if (baseClass.isSealed()) { diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/AddOverrideToEqualsHashCodeToStringFix.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/AddOverrideToEqualsHashCodeToStringFix.kt index 63000975724..599ec4c1d19 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/AddOverrideToEqualsHashCodeToStringFix.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/AddOverrideToEqualsHashCodeToStringFix.kt @@ -16,6 +16,7 @@ package org.jetbrains.kotlin.idea.quickfix +import com.intellij.codeInsight.FileModificationService import com.intellij.codeInsight.intention.IntentionAction import org.jetbrains.kotlin.builtins.KotlinBuiltIns import org.jetbrains.kotlin.diagnostics.Diagnostic @@ -44,6 +45,7 @@ object AddOverrideToEqualsHashCodeToStringActionFactory : KotlinSingleIntentionA } private fun KtNamedFunction.doInvoke() { + if (!FileModificationService.getInstance().preparePsiElementForWrite(this)) return addModifier(OVERRIDE_KEYWORD) removeModifier(PUBLIC_KEYWORD) } diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/ExclExclCallFixes.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/ExclExclCallFixes.kt index 1e7330791f7..1a6eb753a17 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/ExclExclCallFixes.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/ExclExclCallFixes.kt @@ -83,6 +83,8 @@ class AddExclExclCallFix(val psiElement: PsiElement) : ExclExclCallFix() { getExpressionForIntroduceCall() != null override fun invoke(project: Project, editor: Editor?, file: PsiFile?) { + if (!FileModificationService.getInstance().prepareFileForWrite(file)) return + val modifiedExpression = getExpressionForIntroduceCall() ?: return val exclExclExpression = KtPsiFactory(project).createExpressionByPattern("$0!!", modifiedExpression) modifiedExpression.replace(exclExclExpression) diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/SpecifyTypeExplicitlyFix.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/SpecifyTypeExplicitlyFix.kt index b5e631bdb27..84890693931 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/SpecifyTypeExplicitlyFix.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/SpecifyTypeExplicitlyFix.kt @@ -16,6 +16,7 @@ package org.jetbrains.kotlin.idea.quickfix +import com.intellij.codeInsight.FileModificationService import com.intellij.codeInsight.intention.PsiElementBaseIntentionAction import com.intellij.openapi.editor.Editor import com.intellij.openapi.project.Project @@ -30,6 +31,8 @@ class SpecifyTypeExplicitlyFix : PsiElementBaseIntentionAction() { override fun getFamilyName() = "Specify type explicitly" override fun invoke(project: Project, editor: Editor, element: PsiElement) { + if (!FileModificationService.getInstance().preparePsiElementForWrite(element)) return + val declaration = declarationByElement(element)!! val type = SpecifyTypeExplicitlyIntention.getTypeForDeclaration(declaration) SpecifyTypeExplicitlyIntention.addTypeAnnotation(editor, declaration, type) diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/kotlinRefactoringUtil.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/kotlinRefactoringUtil.kt index 537d3d04f03..c9248af80b0 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/kotlinRefactoringUtil.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/kotlinRefactoringUtil.kt @@ -455,7 +455,7 @@ fun PsiElement.canRefactor(): Boolean { this is KtElement || this is PsiMember && language == JavaLanguage.INSTANCE || this is PsiDirectory -> - isWritable && ProjectRootsUtil.isInProjectSource(this) + ProjectRootsUtil.isInProjectSource(this) else -> false }