add missing prepareForWrite() calls
This commit is contained in:
+2
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.idea.inspections
|
package org.jetbrains.kotlin.idea.inspections
|
||||||
|
|
||||||
|
import com.intellij.codeInsight.FileModificationService
|
||||||
import com.intellij.codeInsight.intention.HighPriorityAction
|
import com.intellij.codeInsight.intention.HighPriorityAction
|
||||||
import com.intellij.codeInsight.intention.IntentionAction
|
import com.intellij.codeInsight.intention.IntentionAction
|
||||||
import com.intellij.codeInsight.intention.LowPriorityAction
|
import com.intellij.codeInsight.intention.LowPriorityAction
|
||||||
@@ -167,6 +168,7 @@ abstract class IntentionBasedInspection<TElement : PsiElement>(
|
|||||||
override fun invoke(project: Project, file: PsiFile, startElement: PsiElement, endElement: PsiElement) {
|
override fun invoke(project: Project, file: PsiFile, startElement: PsiElement, endElement: PsiElement) {
|
||||||
assert(startElement == endElement)
|
assert(startElement == endElement)
|
||||||
if (!isAvailable(project, file, startElement, endElement)) return
|
if (!isAvailable(project, file, startElement, endElement)) return
|
||||||
|
if (!FileModificationService.getInstance().prepareFileForWrite(file)) return
|
||||||
|
|
||||||
val editor = startElement.findExistingEditor()
|
val editor = startElement.findExistingEditor()
|
||||||
editor?.caretModel?.moveToOffset(startElement.textOffset)
|
editor?.caretModel?.moveToOffset(startElement.textOffset)
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.idea.intentions
|
package org.jetbrains.kotlin.idea.intentions
|
||||||
|
|
||||||
|
import com.intellij.codeInsight.FileModificationService
|
||||||
import com.intellij.codeInsight.daemon.HighlightDisplayKey
|
import com.intellij.codeInsight.daemon.HighlightDisplayKey
|
||||||
import com.intellij.codeInsight.intention.IntentionAction
|
import com.intellij.codeInsight.intention.IntentionAction
|
||||||
import com.intellij.codeInspection.LocalInspectionEP
|
import com.intellij.codeInspection.LocalInspectionEP
|
||||||
@@ -104,6 +105,7 @@ abstract class SelfTargetingIntention<TElement : PsiElement>(
|
|||||||
final override fun invoke(project: Project, editor: Editor, file: PsiFile): Unit {
|
final override fun invoke(project: Project, editor: Editor, file: PsiFile): Unit {
|
||||||
PsiDocumentManager.getInstance(project).commitAllDocuments()
|
PsiDocumentManager.getInstance(project).commitAllDocuments()
|
||||||
val target = getTarget(editor, file) ?: return
|
val target = getTarget(editor, file) ?: return
|
||||||
|
if (!FileModificationService.getInstance().preparePsiElementForWrite(target)) return
|
||||||
applyTo(target, editor)
|
applyTo(target, editor)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.idea.kdoc
|
package org.jetbrains.kotlin.idea.kdoc
|
||||||
|
|
||||||
|
import com.intellij.codeInsight.FileModificationService
|
||||||
import com.intellij.codeInspection.LocalQuickFix
|
import com.intellij.codeInspection.LocalQuickFix
|
||||||
import com.intellij.codeInspection.ProblemDescriptor
|
import com.intellij.codeInspection.ProblemDescriptor
|
||||||
import com.intellij.codeInspection.ProblemsHolder
|
import com.intellij.codeInspection.ProblemsHolder
|
||||||
@@ -69,6 +70,7 @@ class KDocMissingDocumentationInspection(): AbstractKotlinInspection() {
|
|||||||
override fun getFamilyName(): String = name
|
override fun getFamilyName(): String = name
|
||||||
|
|
||||||
override fun applyFix(project: Project, descriptor: ProblemDescriptor) {
|
override fun applyFix(project: Project, descriptor: ProblemDescriptor) {
|
||||||
|
if (!FileModificationService.getInstance().preparePsiElementForWrite(descriptor.psiElement)) return
|
||||||
val declaration = descriptor.psiElement.getParentOfType<KtNamedDeclaration>(true)
|
val declaration = descriptor.psiElement.getParentOfType<KtNamedDeclaration>(true)
|
||||||
?: throw IllegalStateException("Can't find declaration")
|
?: throw IllegalStateException("Can't find declaration")
|
||||||
declaration.addBefore(KDocElementFactory(project).createKDocFromText("/** */"), declaration.firstChild)
|
declaration.addBefore(KDocElementFactory(project).createKDocFromText("/** */"), declaration.firstChild)
|
||||||
|
|||||||
+3
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.idea.quickfix
|
package org.jetbrains.kotlin.idea.quickfix
|
||||||
|
|
||||||
|
import com.intellij.codeInsight.FileModificationService
|
||||||
import com.intellij.codeInspection.SuppressIntentionAction
|
import com.intellij.codeInspection.SuppressIntentionAction
|
||||||
import com.intellij.openapi.editor.Editor
|
import com.intellij.openapi.editor.Editor
|
||||||
import com.intellij.openapi.project.Project
|
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 isAvailable(project: Project, editor: Editor?, element: PsiElement) = element.isValid
|
||||||
|
|
||||||
override fun invoke(project: Project, editor: Editor?, element: PsiElement) {
|
override fun invoke(project: Project, editor: Editor?, element: PsiElement) {
|
||||||
|
if (!FileModificationService.getInstance().preparePsiElementForWrite(element)) return
|
||||||
|
|
||||||
val id = "\"$suppressKey\""
|
val id = "\"$suppressKey\""
|
||||||
when (suppressAt) {
|
when (suppressAt) {
|
||||||
is KtModifierListOwner ->
|
is KtModifierListOwner ->
|
||||||
|
|||||||
+3
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.idea.core.overrideImplement
|
package org.jetbrains.kotlin.idea.core.overrideImplement
|
||||||
|
|
||||||
|
import com.intellij.codeInsight.FileModificationService
|
||||||
import com.intellij.codeInsight.hint.HintManager
|
import com.intellij.codeInsight.hint.HintManager
|
||||||
import com.intellij.ide.util.MemberChooser
|
import com.intellij.ide.util.MemberChooser
|
||||||
import com.intellij.lang.LanguageCodeInsightActionHandler
|
import com.intellij.lang.LanguageCodeInsightActionHandler
|
||||||
@@ -66,6 +67,8 @@ abstract class OverrideImplementMembersHandler : LanguageCodeInsightActionHandle
|
|||||||
val elementAtCaret = file.findElementAt(editor.caretModel.offset)
|
val elementAtCaret = file.findElementAt(editor.caretModel.offset)
|
||||||
val classOrObject = elementAtCaret?.getNonStrictParentOfType<KtClassOrObject>() ?: return
|
val classOrObject = elementAtCaret?.getNonStrictParentOfType<KtClassOrObject>() ?: return
|
||||||
|
|
||||||
|
if (!FileModificationService.getInstance().prepareFileForWrite(file)) return
|
||||||
|
|
||||||
val members = collectMembersToGenerate(classOrObject)
|
val members = collectMembersToGenerate(classOrObject)
|
||||||
if (members.isEmpty() && !implementAll) {
|
if (members.isEmpty() && !implementAll) {
|
||||||
HintManager.getInstance().showErrorHint(editor, getNoMembersFoundHint())
|
HintManager.getInstance().showErrorHint(editor, getNoMembersFoundHint())
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.idea.inspections
|
package org.jetbrains.kotlin.idea.inspections
|
||||||
|
|
||||||
|
import com.intellij.codeInsight.FileModificationService
|
||||||
import com.intellij.codeInspection.LocalQuickFix
|
import com.intellij.codeInspection.LocalQuickFix
|
||||||
import com.intellij.codeInspection.ProblemDescriptor
|
import com.intellij.codeInspection.ProblemDescriptor
|
||||||
import com.intellij.openapi.project.Project
|
import com.intellij.openapi.project.Project
|
||||||
@@ -32,6 +33,7 @@ open class AddModifierFix(val modifierListOwner: KtModifierListOwner,
|
|||||||
override fun getFamilyName() = text
|
override fun getFamilyName() = text
|
||||||
|
|
||||||
final override fun applyFix(project: Project, descriptor: ProblemDescriptor) {
|
final override fun applyFix(project: Project, descriptor: ProblemDescriptor) {
|
||||||
|
if (!FileModificationService.getInstance().preparePsiElementForWrite(descriptor.psiElement)) return
|
||||||
addModifier(modifierListOwner, modifier)
|
addModifier(modifierListOwner, modifier)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.idea.inspections
|
package org.jetbrains.kotlin.idea.inspections
|
||||||
|
|
||||||
|
import com.intellij.codeInsight.FileModificationService
|
||||||
import com.intellij.codeInspection.*
|
import com.intellij.codeInspection.*
|
||||||
import com.intellij.openapi.project.Project
|
import com.intellij.openapi.project.Project
|
||||||
import com.intellij.psi.PsiElementVisitor
|
import com.intellij.psi.PsiElementVisitor
|
||||||
@@ -77,6 +78,7 @@ class AddVarianceModifierInspection : AbstractKotlinInspection() {
|
|||||||
override fun getFamilyName() = "Add variance"
|
override fun getFamilyName() = "Add variance"
|
||||||
|
|
||||||
override fun applyFix(project: Project, descriptor: ProblemDescriptor) {
|
override fun applyFix(project: Project, descriptor: ProblemDescriptor) {
|
||||||
|
if (!FileModificationService.getInstance().preparePsiElementForWrite(descriptor.psiElement)) return
|
||||||
val typeParameter = descriptor.psiElement as? KtTypeParameter
|
val typeParameter = descriptor.psiElement as? KtTypeParameter
|
||||||
?: throw AssertionError("Add variance fix is used on ${descriptor.psiElement.text}")
|
?: 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)
|
addModifier(typeParameter, if (variance == Variance.IN_VARIANCE) KtTokens.IN_KEYWORD else KtTokens.OUT_KEYWORD)
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.idea.inspections
|
package org.jetbrains.kotlin.idea.inspections
|
||||||
|
|
||||||
|
import com.intellij.codeInsight.FileModificationService
|
||||||
import com.intellij.codeInspection.LocalQuickFix
|
import com.intellij.codeInspection.LocalQuickFix
|
||||||
import com.intellij.codeInspection.ProblemDescriptor
|
import com.intellij.codeInspection.ProblemDescriptor
|
||||||
import com.intellij.codeInspection.ProblemHighlightType
|
import com.intellij.codeInspection.ProblemHighlightType
|
||||||
@@ -124,6 +125,7 @@ class CanBeParameterInspection : AbstractKotlinInspection() {
|
|||||||
override fun getFamilyName() = fix.familyName
|
override fun getFamilyName() = fix.familyName
|
||||||
|
|
||||||
override fun applyFix(project: Project, descriptor: ProblemDescriptor) {
|
override fun applyFix(project: Project, descriptor: ProblemDescriptor) {
|
||||||
|
if (!FileModificationService.getInstance().preparePsiElementForWrite(descriptor.psiElement)) return
|
||||||
parameter.valOrVarKeyword?.delete()
|
parameter.valOrVarKeyword?.delete()
|
||||||
// Delete visibility / open / final / lateinit, if any
|
// Delete visibility / open / final / lateinit, if any
|
||||||
// Retain annotations / vararg
|
// Retain annotations / vararg
|
||||||
|
|||||||
+3
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.idea.inspections
|
package org.jetbrains.kotlin.idea.inspections
|
||||||
|
|
||||||
|
import com.intellij.codeInsight.FileModificationService
|
||||||
import com.intellij.codeInspection.LocalQuickFix
|
import com.intellij.codeInspection.LocalQuickFix
|
||||||
import com.intellij.codeInspection.ProblemDescriptor
|
import com.intellij.codeInspection.ProblemDescriptor
|
||||||
import com.intellij.codeInspection.ProblemHighlightType
|
import com.intellij.codeInspection.ProblemHighlightType
|
||||||
@@ -78,6 +79,8 @@ class CanBePrimaryConstructorPropertyInspection : AbstractKotlinInspection() {
|
|||||||
override fun getFamilyName() = "Move to constructor"
|
override fun getFamilyName() = "Move to constructor"
|
||||||
|
|
||||||
override fun applyFix(project: Project, descriptor: ProblemDescriptor) {
|
override fun applyFix(project: Project, descriptor: ProblemDescriptor) {
|
||||||
|
if (!FileModificationService.getInstance().preparePsiElementForWrite(descriptor.psiElement)) return
|
||||||
|
|
||||||
val commentSaver = CommentSaver(original)
|
val commentSaver = CommentSaver(original)
|
||||||
val isVar = original.isVar
|
val isVar = original.isVar
|
||||||
val modifiers = original.modifierList?.text
|
val modifiers = original.modifierList?.text
|
||||||
|
|||||||
+2
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.idea.inspections
|
package org.jetbrains.kotlin.idea.inspections
|
||||||
|
|
||||||
|
import com.intellij.codeInsight.FileModificationService
|
||||||
import com.intellij.codeInsight.intention.LowPriorityAction
|
import com.intellij.codeInsight.intention.LowPriorityAction
|
||||||
import com.intellij.codeInspection.*
|
import com.intellij.codeInspection.*
|
||||||
import com.intellij.openapi.diagnostic.Logger
|
import com.intellij.openapi.diagnostic.Logger
|
||||||
@@ -204,6 +205,7 @@ class ConflictingExtensionPropertyInspection : AbstractKotlinInspection(), Clean
|
|||||||
UIUtil.invokeLaterIfNeeded {
|
UIUtil.invokeLaterIfNeeded {
|
||||||
project.executeWriteCommand(text) {
|
project.executeWriteCommand(text) {
|
||||||
importsToDelete.forEach { import ->
|
importsToDelete.forEach { import ->
|
||||||
|
if (!FileModificationService.getInstance().preparePsiElementForWrite(import)) return@forEach
|
||||||
try {
|
try {
|
||||||
import.delete()
|
import.delete()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.idea.inspections
|
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.InspectionsBundle
|
||||||
import com.intellij.codeInspection.LocalQuickFix
|
import com.intellij.codeInspection.LocalQuickFix
|
||||||
import com.intellij.codeInspection.ProblemDescriptor
|
import com.intellij.codeInspection.ProblemDescriptor
|
||||||
@@ -42,6 +44,7 @@ object DeleteEqualsAndHashCodeFix : LocalQuickFix {
|
|||||||
override fun getFamilyName() = name
|
override fun getFamilyName() = name
|
||||||
|
|
||||||
override fun applyFix(project: Project, descriptor: ProblemDescriptor) {
|
override fun applyFix(project: Project, descriptor: ProblemDescriptor) {
|
||||||
|
if (!FileModificationService.getInstance().preparePsiElementForWrite(descriptor.psiElement)) return
|
||||||
val objectDeclaration = descriptor.psiElement.getStrictParentOfType<KtObjectDeclaration>() ?: return
|
val objectDeclaration = descriptor.psiElement.getStrictParentOfType<KtObjectDeclaration>() ?: return
|
||||||
val classDescriptor = objectDeclaration.resolveToDescriptorIfAny() as? ClassDescriptor ?: return
|
val classDescriptor = objectDeclaration.resolveToDescriptorIfAny() as? ClassDescriptor ?: return
|
||||||
classDescriptor.findDeclaredEquals(false)?.source?.getPsi()?.delete()
|
classDescriptor.findDeclaredEquals(false)?.source?.getPsi()?.delete()
|
||||||
@@ -61,6 +64,7 @@ sealed class GenerateEqualsOrHashCodeFix : LocalQuickFix {
|
|||||||
override fun getFamilyName() = name
|
override fun getFamilyName() = name
|
||||||
|
|
||||||
override fun applyFix(project: Project, descriptor: ProblemDescriptor) {
|
override fun applyFix(project: Project, descriptor: ProblemDescriptor) {
|
||||||
|
if (!FileModificationService.getInstance().preparePsiElementForWrite(descriptor.psiElement)) return
|
||||||
KotlinGenerateEqualsAndHashcodeAction().doInvoke(project, null, descriptor.psiElement.parent as KtClass)
|
KotlinGenerateEqualsAndHashcodeAction().doInvoke(project, null, descriptor.psiElement.parent as KtClass)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.idea.inspections
|
package org.jetbrains.kotlin.idea.inspections
|
||||||
|
|
||||||
|
import com.intellij.codeInsight.FileModificationService
|
||||||
import com.intellij.codeInspection.*
|
import com.intellij.codeInspection.*
|
||||||
import com.intellij.openapi.project.Project
|
import com.intellij.openapi.project.Project
|
||||||
import com.intellij.psi.PsiElementVisitor
|
import com.intellij.psi.PsiElementVisitor
|
||||||
@@ -56,6 +57,7 @@ class ProtectedInFinalInspection : AbstractKotlinInspection() {
|
|||||||
override fun getFamilyName(): String = name
|
override fun getFamilyName(): String = name
|
||||||
|
|
||||||
override fun applyFix(project: Project, descriptor: ProblemDescriptor) {
|
override fun applyFix(project: Project, descriptor: ProblemDescriptor) {
|
||||||
|
if (!FileModificationService.getInstance().preparePsiElementForWrite(descriptor.psiElement)) return
|
||||||
val modifierListOwner = descriptor.psiElement.getParentOfType<KtModifierListOwner>(true)
|
val modifierListOwner = descriptor.psiElement.getParentOfType<KtModifierListOwner>(true)
|
||||||
?: throw IllegalStateException("Can't find modifier list owner for modifier")
|
?: throw IllegalStateException("Can't find modifier list owner for modifier")
|
||||||
addModifier(modifierListOwner, KtTokens.PRIVATE_KEYWORD)
|
addModifier(modifierListOwner, KtTokens.PRIVATE_KEYWORD)
|
||||||
@@ -68,6 +70,7 @@ class ProtectedInFinalInspection : AbstractKotlinInspection() {
|
|||||||
override fun getFamilyName(): String = name
|
override fun getFamilyName(): String = name
|
||||||
|
|
||||||
override fun applyFix(project: Project, descriptor: ProblemDescriptor) {
|
override fun applyFix(project: Project, descriptor: ProblemDescriptor) {
|
||||||
|
if (!FileModificationService.getInstance().preparePsiElementForWrite(descriptor.psiElement)) return
|
||||||
val modifierListOwner = descriptor.psiElement.getParentOfType<KtModifierListOwner>(true)
|
val modifierListOwner = descriptor.psiElement.getParentOfType<KtModifierListOwner>(true)
|
||||||
?: throw IllegalStateException("Can't find modifier list owner for modifier")
|
?: throw IllegalStateException("Can't find modifier list owner for modifier")
|
||||||
val parentClass = modifierListOwner.getParentOfType<KtClass>(true) ?: return
|
val parentClass = modifierListOwner.getParentOfType<KtClass>(true) ?: return
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.idea.inspections
|
package org.jetbrains.kotlin.idea.inspections
|
||||||
|
|
||||||
|
import com.intellij.codeInsight.FileModificationService
|
||||||
import com.intellij.codeInspection.*
|
import com.intellij.codeInspection.*
|
||||||
import com.intellij.openapi.project.Project
|
import com.intellij.openapi.project.Project
|
||||||
import com.intellij.psi.PsiComment
|
import com.intellij.psi.PsiComment
|
||||||
@@ -63,6 +64,7 @@ class RedundantSemicolonInspection : AbstractKotlinInspection(), CleanupLocalIns
|
|||||||
override fun getFamilyName() = name
|
override fun getFamilyName() = name
|
||||||
|
|
||||||
override fun applyFix(project: Project, descriptor: ProblemDescriptor) {
|
override fun applyFix(project: Project, descriptor: ProblemDescriptor) {
|
||||||
|
if (!FileModificationService.getInstance().preparePsiElementForWrite(descriptor.psiElement)) return
|
||||||
descriptor.psiElement.delete()
|
descriptor.psiElement.delete()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.idea.inspections
|
package org.jetbrains.kotlin.idea.inspections
|
||||||
|
|
||||||
|
import com.intellij.codeInsight.FileModificationService
|
||||||
import com.intellij.codeInspection.LocalQuickFix
|
import com.intellij.codeInspection.LocalQuickFix
|
||||||
import com.intellij.codeInspection.ProblemDescriptor
|
import com.intellij.codeInspection.ProblemDescriptor
|
||||||
import com.intellij.openapi.project.Project
|
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 modifierKeyword = descriptor.psiElement.node.elementType as KtModifierKeywordToken
|
||||||
val modifierListOwner = descriptor.psiElement.getParentOfType<KtModifierListOwner>(true)
|
val modifierListOwner = descriptor.psiElement.getParentOfType<KtModifierListOwner>(true)
|
||||||
?: throw IllegalStateException("Can't find modifier list owner for modifier")
|
?: throw IllegalStateException("Can't find modifier list owner for modifier")
|
||||||
|
if (!FileModificationService.getInstance().preparePsiElementForWrite(modifierListOwner)) return
|
||||||
removeModifier(modifierListOwner, modifierKeyword)
|
removeModifier(modifierListOwner, modifierKeyword)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.idea.inspections
|
package org.jetbrains.kotlin.idea.inspections
|
||||||
|
|
||||||
|
import com.intellij.codeInsight.FileModificationService
|
||||||
import com.intellij.codeInspection.*
|
import com.intellij.codeInspection.*
|
||||||
import com.intellij.openapi.project.Project
|
import com.intellij.openapi.project.Project
|
||||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
||||||
@@ -56,6 +57,8 @@ class RemoveToStringFix: LocalQuickFix {
|
|||||||
|
|
||||||
override fun applyFix(project: Project, descriptor: ProblemDescriptor) {
|
override fun applyFix(project: Project, descriptor: ProblemDescriptor) {
|
||||||
val element = descriptor.psiElement.parent as? KtDotQualifiedExpression ?: return
|
val element = descriptor.psiElement.parent as? KtDotQualifiedExpression ?: return
|
||||||
|
if (!FileModificationService.getInstance().preparePsiElementForWrite(element)) return
|
||||||
|
|
||||||
val receiverExpression = element.receiverExpression
|
val receiverExpression = element.receiverExpression
|
||||||
if (receiverExpression is KtNameReferenceExpression) {
|
if (receiverExpression is KtNameReferenceExpression) {
|
||||||
val templateEntry = receiverExpression.parent.parent
|
val templateEntry = receiverExpression.parent.parent
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.idea.inspections
|
package org.jetbrains.kotlin.idea.inspections
|
||||||
|
|
||||||
|
import com.intellij.codeInsight.FileModificationService
|
||||||
import com.intellij.codeInspection.*
|
import com.intellij.codeInspection.*
|
||||||
import com.intellij.openapi.project.Project
|
import com.intellij.openapi.project.Project
|
||||||
import com.intellij.psi.PsiElement
|
import com.intellij.psi.PsiElement
|
||||||
@@ -116,6 +117,8 @@ class UnusedReceiverParameterInspection : AbstractKotlinInspection() {
|
|||||||
|
|
||||||
override fun applyFix(project: Project, descriptor: ProblemDescriptor) {
|
override fun applyFix(project: Project, descriptor: ProblemDescriptor) {
|
||||||
val element = descriptor.psiElement
|
val element = descriptor.psiElement
|
||||||
|
if (!FileModificationService.getInstance().preparePsiElementForWrite(element)) return
|
||||||
|
|
||||||
val function = element.parent as? KtCallableDeclaration ?: return
|
val function = element.parent as? KtCallableDeclaration ?: return
|
||||||
val callableDescriptor = function.analyze()[BindingContext.DECLARATION_TO_DESCRIPTOR, function] as? CallableDescriptor ?: return
|
val callableDescriptor = function.analyze()[BindingContext.DECLARATION_TO_DESCRIPTOR, function] as? CallableDescriptor ?: return
|
||||||
runChangeSignature(project, callableDescriptor, configureChangeSignature(), element, name)
|
runChangeSignature(project, callableDescriptor, configureChangeSignature(), element, name)
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
package org.jetbrains.kotlin.idea.intentions
|
package org.jetbrains.kotlin.idea.intentions
|
||||||
|
|
||||||
import com.intellij.codeInsight.CodeInsightUtil
|
import com.intellij.codeInsight.CodeInsightUtil
|
||||||
|
import com.intellij.codeInsight.FileModificationService
|
||||||
import com.intellij.codeInsight.daemon.impl.quickfix.CreateClassKind
|
import com.intellij.codeInsight.daemon.impl.quickfix.CreateClassKind
|
||||||
import com.intellij.codeInsight.intention.impl.CreateClassDialog
|
import com.intellij.codeInsight.intention.impl.CreateClassDialog
|
||||||
import com.intellij.openapi.application.ApplicationManager
|
import com.intellij.openapi.application.ApplicationManager
|
||||||
@@ -79,6 +80,7 @@ class CreateKotlinSubClassIntention : SelfTargetingRangeIntention<KtClass>(KtCla
|
|||||||
|
|
||||||
override fun applyTo(element: KtClass, editor: Editor?) {
|
override fun applyTo(element: KtClass, editor: Editor?) {
|
||||||
if (editor == null) throw IllegalArgumentException("This intention requires an 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 name = element.name ?: throw IllegalStateException("This intention should not be applied to anonymous classes")
|
||||||
val baseClass = element
|
val baseClass = element
|
||||||
if (baseClass.isSealed()) {
|
if (baseClass.isSealed()) {
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.idea.quickfix
|
package org.jetbrains.kotlin.idea.quickfix
|
||||||
|
|
||||||
|
import com.intellij.codeInsight.FileModificationService
|
||||||
import com.intellij.codeInsight.intention.IntentionAction
|
import com.intellij.codeInsight.intention.IntentionAction
|
||||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||||
import org.jetbrains.kotlin.diagnostics.Diagnostic
|
import org.jetbrains.kotlin.diagnostics.Diagnostic
|
||||||
@@ -44,6 +45,7 @@ object AddOverrideToEqualsHashCodeToStringActionFactory : KotlinSingleIntentionA
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun KtNamedFunction.doInvoke() {
|
private fun KtNamedFunction.doInvoke() {
|
||||||
|
if (!FileModificationService.getInstance().preparePsiElementForWrite(this)) return
|
||||||
addModifier(OVERRIDE_KEYWORD)
|
addModifier(OVERRIDE_KEYWORD)
|
||||||
removeModifier(PUBLIC_KEYWORD)
|
removeModifier(PUBLIC_KEYWORD)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -83,6 +83,8 @@ class AddExclExclCallFix(val psiElement: PsiElement) : ExclExclCallFix() {
|
|||||||
getExpressionForIntroduceCall() != null
|
getExpressionForIntroduceCall() != null
|
||||||
|
|
||||||
override fun invoke(project: Project, editor: Editor?, file: PsiFile?) {
|
override fun invoke(project: Project, editor: Editor?, file: PsiFile?) {
|
||||||
|
if (!FileModificationService.getInstance().prepareFileForWrite(file)) return
|
||||||
|
|
||||||
val modifiedExpression = getExpressionForIntroduceCall() ?: return
|
val modifiedExpression = getExpressionForIntroduceCall() ?: return
|
||||||
val exclExclExpression = KtPsiFactory(project).createExpressionByPattern("$0!!", modifiedExpression)
|
val exclExclExpression = KtPsiFactory(project).createExpressionByPattern("$0!!", modifiedExpression)
|
||||||
modifiedExpression.replace(exclExclExpression)
|
modifiedExpression.replace(exclExclExpression)
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.idea.quickfix
|
package org.jetbrains.kotlin.idea.quickfix
|
||||||
|
|
||||||
|
import com.intellij.codeInsight.FileModificationService
|
||||||
import com.intellij.codeInsight.intention.PsiElementBaseIntentionAction
|
import com.intellij.codeInsight.intention.PsiElementBaseIntentionAction
|
||||||
import com.intellij.openapi.editor.Editor
|
import com.intellij.openapi.editor.Editor
|
||||||
import com.intellij.openapi.project.Project
|
import com.intellij.openapi.project.Project
|
||||||
@@ -30,6 +31,8 @@ class SpecifyTypeExplicitlyFix : PsiElementBaseIntentionAction() {
|
|||||||
override fun getFamilyName() = "Specify type explicitly"
|
override fun getFamilyName() = "Specify type explicitly"
|
||||||
|
|
||||||
override fun invoke(project: Project, editor: Editor, element: PsiElement) {
|
override fun invoke(project: Project, editor: Editor, element: PsiElement) {
|
||||||
|
if (!FileModificationService.getInstance().preparePsiElementForWrite(element)) return
|
||||||
|
|
||||||
val declaration = declarationByElement(element)!!
|
val declaration = declarationByElement(element)!!
|
||||||
val type = SpecifyTypeExplicitlyIntention.getTypeForDeclaration(declaration)
|
val type = SpecifyTypeExplicitlyIntention.getTypeForDeclaration(declaration)
|
||||||
SpecifyTypeExplicitlyIntention.addTypeAnnotation(editor, declaration, type)
|
SpecifyTypeExplicitlyIntention.addTypeAnnotation(editor, declaration, type)
|
||||||
|
|||||||
@@ -455,7 +455,7 @@ fun PsiElement.canRefactor(): Boolean {
|
|||||||
this is KtElement ||
|
this is KtElement ||
|
||||||
this is PsiMember && language == JavaLanguage.INSTANCE ||
|
this is PsiMember && language == JavaLanguage.INSTANCE ||
|
||||||
this is PsiDirectory ->
|
this is PsiDirectory ->
|
||||||
isWritable && ProjectRootsUtil.isInProjectSource(this)
|
ProjectRootsUtil.isInProjectSource(this)
|
||||||
else ->
|
else ->
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user