mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
replace sequential task with "write" progress
This commit is contained in:
+9
@@ -753,6 +753,15 @@ public class HighlightControlFlowUtil {
|
||||
}
|
||||
}
|
||||
effectivelyFinal = notAccessedForWriting(variable, new LocalSearchScope(scope));
|
||||
if (effectivelyFinal) {
|
||||
return ReferencesSearch.search(variable).forEach(ref -> {
|
||||
PsiElement element = ref.getElement();
|
||||
if (element instanceof PsiReferenceExpression && PsiUtil.isAccessedForWriting((PsiExpression)element)) {
|
||||
return !ControlFlowUtil.isVariableAssignedInLoop((PsiReferenceExpression)element, variable);
|
||||
}
|
||||
return true;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
return effectivelyFinal;
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
*/
|
||||
package com.intellij.util;
|
||||
|
||||
import com.intellij.openapi.progress.ProgressIndicator;
|
||||
|
||||
/**
|
||||
* Defines general contract for processing that may be executed by parts, i.e. it remembers the state after every iteration
|
||||
* and allows to resume the processing any time.
|
||||
@@ -41,6 +43,10 @@ public interface SequentialTask {
|
||||
*/
|
||||
boolean iteration();
|
||||
|
||||
default boolean iteration(ProgressIndicator indicator) {
|
||||
return iteration();
|
||||
}
|
||||
|
||||
/**
|
||||
* Asks current task to stop the processing (if any).
|
||||
*/
|
||||
|
||||
+10
-14
@@ -25,6 +25,8 @@ import com.intellij.codeInspection.*;
|
||||
import com.intellij.codeInspection.ex.InspectionToolWrapper;
|
||||
import com.intellij.codeInspection.ex.LocalInspectionToolWrapper;
|
||||
import com.intellij.codeInspection.ex.PerformFixesModalTask;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.impl.ApplicationImpl;
|
||||
import com.intellij.openapi.command.CommandProcessor;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
@@ -34,7 +36,6 @@ import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.intellij.util.SequentialModalProgressTask;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -97,17 +98,15 @@ public class CleanupInspectionIntention implements IntentionAction, HighPriority
|
||||
@NotNull String presentationText,
|
||||
@NotNull List<ProblemDescriptor> descriptions,
|
||||
@Nullable Class quickfixClass) {
|
||||
final SequentialModalProgressTask progressTask =
|
||||
new SequentialModalProgressTask(project, presentationText, true);
|
||||
|
||||
final boolean isBatch = quickfixClass != null && BatchQuickFix.class.isAssignableFrom(quickfixClass);
|
||||
final AbstractPerformFixesTask fixesTask = isBatch ?
|
||||
new PerformBatchFixesTask(project, descriptions.toArray(ProblemDescriptor.EMPTY_ARRAY), progressTask, quickfixClass) :
|
||||
new PerformFixesTask(project, descriptions.toArray(ProblemDescriptor.EMPTY_ARRAY), progressTask, quickfixClass);
|
||||
new PerformBatchFixesTask(project, descriptions.toArray(ProblemDescriptor.EMPTY_ARRAY), quickfixClass) :
|
||||
new PerformFixesTask(project, descriptions.toArray(ProblemDescriptor.EMPTY_ARRAY), quickfixClass);
|
||||
CommandProcessor.getInstance().executeCommand(project, () -> {
|
||||
CommandProcessor.getInstance().markCurrentCommandAsGlobal(project);
|
||||
progressTask.setMinIterationTime(200);
|
||||
progressTask.setTask(fixesTask);
|
||||
ProgressManager.getInstance().run(progressTask);
|
||||
((ApplicationImpl)ApplicationManager.getApplication())
|
||||
.runWriteActionWithProgressInDispatchThread(presentationText, project, null, null, fixesTask::doRun);
|
||||
}, presentationText, null);
|
||||
return fixesTask;
|
||||
}
|
||||
@@ -134,9 +133,8 @@ public class CleanupInspectionIntention implements IntentionAction, HighPriority
|
||||
|
||||
public AbstractPerformFixesTask(@NotNull Project project,
|
||||
@NotNull CommonProblemDescriptor[] descriptors,
|
||||
@NotNull SequentialModalProgressTask task,
|
||||
@Nullable Class quickfixClass) {
|
||||
super(project, descriptors, task);
|
||||
super(project, descriptors);
|
||||
myQuickfixClass = quickfixClass;
|
||||
}
|
||||
|
||||
@@ -171,9 +169,8 @@ public class CleanupInspectionIntention implements IntentionAction, HighPriority
|
||||
|
||||
public PerformBatchFixesTask(@NotNull Project project,
|
||||
@NotNull CommonProblemDescriptor[] descriptors,
|
||||
@NotNull SequentialModalProgressTask task,
|
||||
@NotNull Class quickfixClass) {
|
||||
super(project, descriptors, task, quickfixClass);
|
||||
super(project, descriptors, quickfixClass);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -209,9 +206,8 @@ public class CleanupInspectionIntention implements IntentionAction, HighPriority
|
||||
private static class PerformFixesTask extends AbstractPerformFixesTask {
|
||||
public PerformFixesTask(@NotNull Project project,
|
||||
@NotNull CommonProblemDescriptor[] descriptors,
|
||||
@NotNull SequentialModalProgressTask task,
|
||||
@Nullable Class quickFixClass) {
|
||||
super(project, descriptors, task, quickFixClass);
|
||||
super(project, descriptors, quickFixClass);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -20,12 +20,10 @@ import com.intellij.codeInspection.ProblemDescriptor;
|
||||
import com.intellij.codeInspection.QuickFix;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.progress.ProgressIndicator;
|
||||
import com.intellij.openapi.project.DumbService;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiDocumentManager;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.presentation.java.SymbolPresentationUtil;
|
||||
import com.intellij.util.SequentialModalProgressTask;
|
||||
import com.intellij.util.SequentialTask;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -33,16 +31,13 @@ public abstract class PerformFixesModalTask implements SequentialTask {
|
||||
@NotNull
|
||||
protected final Project myProject;
|
||||
private final CommonProblemDescriptor[] myDescriptors;
|
||||
private final SequentialModalProgressTask myTask;
|
||||
private final PsiDocumentManager myDocumentManager;
|
||||
private int myCount = 0;
|
||||
|
||||
public PerformFixesModalTask(@NotNull Project project,
|
||||
@NotNull CommonProblemDescriptor[] descriptors,
|
||||
@NotNull SequentialModalProgressTask task) {
|
||||
@NotNull CommonProblemDescriptor[] descriptors) {
|
||||
myProject = project;
|
||||
myDescriptors = descriptors;
|
||||
myTask = task;
|
||||
myDocumentManager = PsiDocumentManager.getInstance(myProject);
|
||||
}
|
||||
|
||||
@@ -57,16 +52,20 @@ public abstract class PerformFixesModalTask implements SequentialTask {
|
||||
|
||||
@Override
|
||||
public boolean iteration() {
|
||||
if (DumbService.getInstance(myProject).isDumb()) {
|
||||
//wait in progress until smart
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void doRun(ProgressIndicator indicator) {
|
||||
while (!isDone()) {
|
||||
if (indicator.isCanceled()) {
|
||||
break;
|
||||
}
|
||||
catch (InterruptedException ignore) { }
|
||||
return false;
|
||||
iteration(indicator);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean iteration(ProgressIndicator indicator) {
|
||||
final CommonProblemDescriptor descriptor = myDescriptors[myCount++];
|
||||
ProgressIndicator indicator = myTask.getIndicator();
|
||||
if (indicator != null) {
|
||||
indicator.setFraction((double)myCount / myDescriptors.length);
|
||||
String presentableText = "usages";
|
||||
|
||||
@@ -33,6 +33,7 @@ import com.intellij.openapi.actionSystem.*;
|
||||
import com.intellij.openapi.actionSystem.ex.CustomComponentAction;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.ReadAction;
|
||||
import com.intellij.openapi.application.impl.ApplicationImpl;
|
||||
import com.intellij.openapi.command.CommandProcessor;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.progress.ProcessCanceledException;
|
||||
@@ -48,7 +49,6 @@ import com.intellij.psi.PsiDocumentManager;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.ui.ClickListener;
|
||||
import com.intellij.util.SequentialModalProgressTask;
|
||||
import com.intellij.util.ui.JBUI;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import gnu.trove.THashSet;
|
||||
@@ -124,7 +124,7 @@ public class QuickFixAction extends AnAction implements CustomComponentAction {
|
||||
Ref<CommonProblemDescriptor[]> descriptors = Ref.create();
|
||||
Set<VirtualFile> readOnlyFiles = new THashSet<>();
|
||||
//TODO revise when jdk9 arrives. Until then this redundant cast is a workaround to compile under jdk9 b169
|
||||
if (!ProgressManager.getInstance().runProcessWithProgressSynchronously((Runnable)() -> ReadAction.run(() -> {
|
||||
if (!ProgressManager.getInstance().runProcessWithProgressSynchronously(() -> ReadAction.run(() -> {
|
||||
final ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
|
||||
indicator.setText("Checking problem descriptors...");
|
||||
descriptors.set(tree.getSelectedDescriptors(true, readOnlyFiles, false, false));
|
||||
@@ -178,11 +178,9 @@ public class QuickFixAction extends AnAction implements CustomComponentAction {
|
||||
assert templatePresentationText != null;
|
||||
CommandProcessor.getInstance().executeCommand(project, () -> {
|
||||
CommandProcessor.getInstance().markCurrentCommandAsGlobal(project);
|
||||
final SequentialModalProgressTask progressTask =
|
||||
new SequentialModalProgressTask(project, templatePresentationText, true);
|
||||
progressTask.setMinIterationTime(200);
|
||||
progressTask.setTask(new PerformFixesTask(project, descriptors, ignoredElements, progressTask, context));
|
||||
ProgressManager.getInstance().run(progressTask);
|
||||
PerformFixesTask performFixesTask = new PerformFixesTask(project, descriptors, ignoredElements, context);
|
||||
((ApplicationImpl)ApplicationManager.getApplication())
|
||||
.runWriteActionWithProgressInDispatchThread(templatePresentationText, project, null, null, performFixesTask::doRun);
|
||||
}, templatePresentationText, null);
|
||||
}
|
||||
|
||||
@@ -248,13 +246,7 @@ public class QuickFixAction extends AnAction implements CustomComponentAction {
|
||||
if (containingFile1 == containingFile2) {
|
||||
int i1 = element1.getTextOffset();
|
||||
int i2 = element2.getTextOffset();
|
||||
if (i1 < i2) {
|
||||
return 1;
|
||||
}
|
||||
if (i1 > i2){
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
return Integer.compare(i2, i1);
|
||||
}
|
||||
return containingFile1.getName().compareTo(containingFile2.getName());
|
||||
}
|
||||
@@ -341,9 +333,8 @@ public class QuickFixAction extends AnAction implements CustomComponentAction {
|
||||
PerformFixesTask(@NotNull Project project,
|
||||
@NotNull CommonProblemDescriptor[] descriptors,
|
||||
@NotNull Set<PsiElement> ignoredElements,
|
||||
@NotNull SequentialModalProgressTask task,
|
||||
@NotNull GlobalInspectionContextImpl context) {
|
||||
super(project, descriptors, task);
|
||||
super(project, descriptors);
|
||||
myContext = context;
|
||||
myIgnoredElements = ignoredElements;
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@ public class SequentialModalProgressTask extends Task.Modal {
|
||||
long start = System.currentTimeMillis();
|
||||
try {
|
||||
while (!task.isDone() && System.currentTimeMillis() - start < myMinIterationTime) {
|
||||
task.iteration();
|
||||
task.iteration(indicator);
|
||||
}
|
||||
}
|
||||
catch (RuntimeException e) {
|
||||
|
||||
Reference in New Issue
Block a user