mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
WriteActionAware: marker to skip containing write action, e.g. when local fix would show dialog or progress, so the write action would be started inside action itself
This commit is contained in:
+5
@@ -115,6 +115,11 @@ public class MethodParameterFix extends LocalQuickFixAndIntentionActionOnPsiElem
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean startInWriteAction() {
|
||||
return false;
|
||||
}
|
||||
|
||||
private ParameterInfoImpl[] getNewParametersInfo(PsiMethod method) throws IncorrectOperationException {
|
||||
List<ParameterInfoImpl> result = new ArrayList<ParameterInfoImpl>();
|
||||
PsiParameter[] parameters = method.getParameterList().getParameters();
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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<D extends CommonProblemDescriptor> {
|
||||
public interface QuickFix<D extends CommonProblemDescriptor> extends WriteActionAware {
|
||||
QuickFix[] EMPTY_ARRAY = new QuickFix[0];
|
||||
|
||||
/**
|
||||
|
||||
@@ -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() {
|
||||
|
||||
+5
-10
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+5
@@ -42,6 +42,11 @@ public class MethodMayBeStaticInspection extends MethodMayBeStaticInspectionBase
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean startInWriteAction() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getName() {
|
||||
|
||||
+5
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,4 +59,9 @@ public class PyMakePublicQuickFix implements LocalQuickFix {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean startInWriteAction() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user