diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/MethodParameterFix.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/MethodParameterFix.java index 3ce3b66b3835..cf7fa5c74550 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/MethodParameterFix.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/MethodParameterFix.java @@ -115,6 +115,11 @@ public class MethodParameterFix extends LocalQuickFixAndIntentionActionOnPsiElem } } + @Override + public boolean startInWriteAction() { + return false; + } + private ParameterInfoImpl[] getNewParametersInfo(PsiMethod method) throws IncorrectOperationException { List result = new ArrayList(); PsiParameter[] parameters = method.getParameterList().getParameters(); diff --git a/platform/analysis-api/src/com/intellij/codeInsight/intention/IntentionAction.java b/platform/analysis-api/src/com/intellij/codeInsight/intention/IntentionAction.java index 8c2a8c5c51e2..175fc42682df 100644 --- a/platform/analysis-api/src/com/intellij/codeInsight/intention/IntentionAction.java +++ b/platform/analysis-api/src/com/intellij/codeInsight/intention/IntentionAction.java @@ -39,7 +39,7 @@ import org.jetbrains.annotations.NotNull; * * @see IntentionManager#registerIntentionAndMetaData(IntentionAction, String...) */ -public interface IntentionAction { +public interface IntentionAction extends WriteActionAware { IntentionAction[] EMPTY_ARRAY = new IntentionAction[0]; /** * Returns text to be shown in the list of available actions, if this action diff --git a/platform/analysis-api/src/com/intellij/codeInsight/intention/WriteActionAware.java b/platform/analysis-api/src/com/intellij/codeInsight/intention/WriteActionAware.java new file mode 100644 index 000000000000..0c02b977b746 --- /dev/null +++ b/platform/analysis-api/src/com/intellij/codeInsight/intention/WriteActionAware.java @@ -0,0 +1,32 @@ +/* + * Copyright 2000-2016 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.codeInsight.intention; + +import com.intellij.openapi.application.Application; + +public interface WriteActionAware { + /** + * Indicate whether this action should be invoked inside write action. + * Should return false if e.g. modal dialog is shown inside the action. + * If false is returned the action itself is responsible for starting write action + * when needed, by calling {@link Application#runWriteAction(Runnable)}. + * + * @return true if the action requires a write action, false otherwise. + */ + default boolean startInWriteAction() { + return true; + } +} diff --git a/platform/analysis-api/src/com/intellij/codeInspection/QuickFix.java b/platform/analysis-api/src/com/intellij/codeInspection/QuickFix.java index ae6b97a0421e..c64c80809823 100644 --- a/platform/analysis-api/src/com/intellij/codeInspection/QuickFix.java +++ b/platform/analysis-api/src/com/intellij/codeInspection/QuickFix.java @@ -15,6 +15,7 @@ */ package com.intellij.codeInspection; +import com.intellij.codeInsight.intention.WriteActionAware; import com.intellij.openapi.project.Project; import org.jetbrains.annotations.Nls; import org.jetbrains.annotations.NotNull; @@ -26,7 +27,7 @@ import org.jetbrains.annotations.NotNull; * @since 6.0 * @see CommonProblemDescriptor#getFixes() */ -public interface QuickFix { +public interface QuickFix extends WriteActionAware { QuickFix[] EMPTY_ARRAY = new QuickFix[0]; /** diff --git a/platform/analysis-impl/src/com/intellij/codeInspection/ex/QuickFixWrapper.java b/platform/analysis-impl/src/com/intellij/codeInspection/ex/QuickFixWrapper.java index 251226105993..774ee7101b93 100644 --- a/platform/analysis-impl/src/com/intellij/codeInspection/ex/QuickFixWrapper.java +++ b/platform/analysis-impl/src/com/intellij/codeInspection/ex/QuickFixWrapper.java @@ -92,8 +92,7 @@ public class QuickFixWrapper implements IntentionAction { @Override public boolean startInWriteAction() { - final LocalQuickFix fix = getFix(); - return !(fix instanceof IntentionAction) || ((IntentionAction)fix).startInWriteAction(); + return getFix().startInWriteAction(); } public LocalQuickFix getFix() { diff --git a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/RenameElementFix.java b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/RenameElementFix.java index d993b56a5446..423792a00e92 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/RenameElementFix.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/RenameElementFix.java @@ -75,15 +75,10 @@ public class RenameElementFix extends LocalQuickFixAndIntentionActionOnPsiElemen @NotNull final PsiElement startElement, @NotNull PsiElement endElement) { if (isAvailable(project, null, file)) { - new WriteCommandAction(project) { - @Override - protected void run(@NotNull Result result) throws Throwable { - LOG.assertTrue(file == startElement.getContainingFile()); - if (!FileModificationService.getInstance().prepareFileForWrite(file)) return; - RenameProcessor processor = new RenameProcessor(project, startElement, myNewName, false, false); - processor.run(); - } - }.execute(); + LOG.assertTrue(file == startElement.getContainingFile()); + if (!FileModificationService.getInstance().prepareFileForWrite(file)) return; + RenameProcessor processor = new RenameProcessor(project, startElement, myNewName, false, false); + processor.run(); } } @@ -102,6 +97,6 @@ public class RenameElementFix extends LocalQuickFixAndIntentionActionOnPsiElemen @Override public boolean startInWriteAction() { - return true; + return false; } } diff --git a/platform/lang-impl/src/com/intellij/codeInspection/ex/PerformFixesModalTask.java b/platform/lang-impl/src/com/intellij/codeInspection/ex/PerformFixesModalTask.java index 96281b57098f..fc5b3964730e 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/ex/PerformFixesModalTask.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/ex/PerformFixesModalTask.java @@ -77,13 +77,11 @@ public abstract class PerformFixesModalTask implements SequentialTask { final QuickFix[] fixes = descriptor.getFixes(); if (fixes != null) { for (QuickFix fix : fixes) { - if (fix instanceof IntentionAction) { - if (!((IntentionAction)fix).startInWriteAction()) { - runInReadAction[0] = true; - } else { - runInReadAction[0] = false; - break; - } + if (!fix.startInWriteAction()) { + runInReadAction[0] = true; + } else { + runInReadAction[0] = false; + break; } } } diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/performance/MethodMayBeStaticInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/performance/MethodMayBeStaticInspection.java index 36230a3e8d85..093004bf75f8 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/performance/MethodMayBeStaticInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/performance/MethodMayBeStaticInspection.java @@ -42,6 +42,11 @@ public class MethodMayBeStaticInspection extends MethodMayBeStaticInspectionBase } } + @Override + public boolean startInWriteAction() { + return false; + } + @Override @NotNull public String getName() { diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/annotator/intentions/GrMoveToDirFix.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/annotator/intentions/GrMoveToDirFix.java index 3e3fb880f373..6637825aa528 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/annotator/intentions/GrMoveToDirFix.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/annotator/intentions/GrMoveToDirFix.java @@ -81,4 +81,9 @@ public class GrMoveToDirFix extends GroovyFix { } new MoveFilesOrDirectoriesProcessor(project, new PsiElement[]{file}, directory, false, false, false, null, null).run(); } + + @Override + public boolean startInWriteAction() { + return false; + } } diff --git a/python/src/com/jetbrains/python/inspections/quickfix/PyMakePublicQuickFix.java b/python/src/com/jetbrains/python/inspections/quickfix/PyMakePublicQuickFix.java index 60dba50130c8..b6c7507bc6f5 100644 --- a/python/src/com/jetbrains/python/inspections/quickfix/PyMakePublicQuickFix.java +++ b/python/src/com/jetbrains/python/inspections/quickfix/PyMakePublicQuickFix.java @@ -59,4 +59,9 @@ public class PyMakePublicQuickFix implements LocalQuickFix { } } } + + @Override + public boolean startInWriteAction() { + return false; + } } diff --git a/python/src/com/jetbrains/python/inspections/quickfix/RenameParameterQuickFix.java b/python/src/com/jetbrains/python/inspections/quickfix/RenameParameterQuickFix.java index c30bf35a1f48..7869568c6203 100644 --- a/python/src/com/jetbrains/python/inspections/quickfix/RenameParameterQuickFix.java +++ b/python/src/com/jetbrains/python/inspections/quickfix/RenameParameterQuickFix.java @@ -52,4 +52,9 @@ public class RenameParameterQuickFix implements LocalQuickFix { public String getName() { return PyBundle.message("QFIX.rename.parameter.to.$0", myNewName); } + + @Override + public boolean startInWriteAction() { + return false; + } }