use of com.intellij.util.SequentialModalProgressTask in project android by JetBrains.
the class AndroidInferNullityAnnotationAction method applyRunnable.
// Intellij code from InferNullityAnnotationsAction.
private static Runnable applyRunnable(Project project, Computable<UsageInfo[]> computable) {
return () -> {
LocalHistoryAction action = LocalHistory.getInstance().startAction(INFER_NULLITY_ANNOTATIONS);
try {
new WriteCommandAction(project, INFER_NULLITY_ANNOTATIONS) {
@Override
protected void run(@NotNull Result result) throws Throwable {
UsageInfo[] infos = computable.compute();
if (infos.length > 0) {
Set<PsiElement> elements = new LinkedHashSet<>();
for (UsageInfo info : infos) {
PsiElement element = info.getElement();
if (element != null) {
ContainerUtil.addIfNotNull(elements, element.getContainingFile());
}
}
if (!FileModificationService.getInstance().preparePsiElementsForWrite(elements))
return;
SequentialModalProgressTask progressTask = new SequentialModalProgressTask(project, INFER_NULLITY_ANNOTATIONS, false);
progressTask.setMinIterationTime(200);
progressTask.setTask(new AnnotateTask(project, progressTask, infos));
ProgressManager.getInstance().run(progressTask);
} else {
NullityInferrer.nothingFoundMessage(project);
}
}
}.execute();
} finally {
action.finish();
}
};
}
use of com.intellij.util.SequentialModalProgressTask in project intellij-community by JetBrains.
the class QuickFixAction method performFixesInBatch.
protected void performFixesInBatch(@NotNull Project project, @NotNull CommonProblemDescriptor[] descriptors, @NotNull GlobalInspectionContextImpl context, Set<PsiElement> ignoredElements) {
final String templatePresentationText = getTemplatePresentation().getText();
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);
}, templatePresentationText, null);
}
use of com.intellij.util.SequentialModalProgressTask in project intellij-community by JetBrains.
the class InferNullityAnnotationsAction method applyRunnable.
private static Runnable applyRunnable(final Project project, final Computable<UsageInfo[]> computable) {
return () -> {
final LocalHistoryAction action = LocalHistory.getInstance().startAction(INFER_NULLITY_ANNOTATIONS);
try {
new WriteCommandAction(project, INFER_NULLITY_ANNOTATIONS) {
@Override
protected void run(@NotNull Result result) throws Throwable {
final UsageInfo[] infos = computable.compute();
if (infos.length > 0) {
final Set<PsiElement> elements = new LinkedHashSet<>();
for (UsageInfo info : infos) {
final PsiElement element = info.getElement();
if (element != null) {
ContainerUtil.addIfNotNull(elements, element.getContainingFile());
}
}
if (!FileModificationService.getInstance().preparePsiElementsForWrite(elements))
return;
final SequentialModalProgressTask progressTask = new SequentialModalProgressTask(project, INFER_NULLITY_ANNOTATIONS, false);
progressTask.setMinIterationTime(200);
progressTask.setTask(new AnnotateTask(project, progressTask, infos));
ProgressManager.getInstance().run(progressTask);
} else {
NullityInferrer.nothingFoundMessage(project);
}
}
}.execute();
} finally {
action.finish();
}
};
}
use of com.intellij.util.SequentialModalProgressTask in project intellij-community by JetBrains.
the class OptimizeImportsTask method performOperation.
@Override
public void performOperation(final Project project, final Set<PsiJavaFile> javaFiles) {
CodeStyleManager.getInstance(project).performActionWithFormatterDisabled(new Runnable() {
@Override
public void run() {
PsiDocumentManager.getInstance(project).commitAllDocuments();
}
});
final List<SmartPsiElementPointer<PsiImportStatementBase>> redundants = new ArrayList<>();
final Runnable findRedundantImports = () -> ReadAction.run(() -> {
final JavaCodeStyleManager styleManager = JavaCodeStyleManager.getInstance(project);
final ProgressIndicator progressIndicator = ProgressManager.getInstance().getProgressIndicator();
final SmartPointerManager pointerManager = SmartPointerManager.getInstance(project);
int i = 0;
final int fileCount = javaFiles.size();
for (PsiJavaFile file : javaFiles) {
if (file.isValid()) {
final VirtualFile virtualFile = file.getVirtualFile();
if (virtualFile != null) {
if (progressIndicator != null) {
progressIndicator.setText2(virtualFile.getPresentableUrl());
progressIndicator.setFraction((double) i++ / fileCount);
}
final Collection<PsiImportStatementBase> perFile = styleManager.findRedundantImports(file);
if (perFile != null) {
for (PsiImportStatementBase redundant : perFile) {
redundants.add(pointerManager.createSmartPsiElementPointer(redundant));
}
}
}
}
}
});
if (!ProgressManager.getInstance().runProcessWithProgressSynchronously(findRedundantImports, REMOVING_REDUNDANT_IMPORTS_TITLE, false, project))
return;
ApplicationManager.getApplication().runWriteAction(() -> {
final SequentialModalProgressTask progressTask = new SequentialModalProgressTask(project, REMOVING_REDUNDANT_IMPORTS_TITLE, false);
progressTask.setMinIterationTime(200);
progressTask.setTask(new OptimizeImportsTask(progressTask, redundants));
ProgressManager.getInstance().run(progressTask);
});
}
use of com.intellij.util.SequentialModalProgressTask in project android by JetBrains.
the class InferSupportAnnotationsAction method applyRunnable.
private static Runnable applyRunnable(Project project, Computable<UsageInfo[]> computable) {
return () -> {
LocalHistoryAction action = LocalHistory.getInstance().startAction(INFER_SUPPORT_ANNOTATIONS);
try {
new WriteCommandAction(project, INFER_SUPPORT_ANNOTATIONS) {
@Override
protected void run(@NotNull Result result) throws Throwable {
UsageInfo[] infos = computable.compute();
if (infos.length > 0) {
Set<PsiElement> elements = new LinkedHashSet<>();
for (UsageInfo info : infos) {
PsiElement element = info.getElement();
if (element != null) {
PsiFile containingFile = element.getContainingFile();
// Skip results in .class files; these are typically from extracted AAR files
VirtualFile virtualFile = containingFile.getVirtualFile();
if (virtualFile.getFileType().isBinary()) {
continue;
}
ContainerUtil.addIfNotNull(elements, containingFile);
}
}
if (!FileModificationService.getInstance().preparePsiElementsForWrite(elements))
return;
SequentialModalProgressTask progressTask = new SequentialModalProgressTask(project, INFER_SUPPORT_ANNOTATIONS, false);
progressTask.setMinIterationTime(200);
progressTask.setTask(new AnnotateTask(project, progressTask, infos));
ProgressManager.getInstance().run(progressTask);
} else {
InferSupportAnnotations.nothingFoundMessage(project);
}
}
}.execute();
} finally {
action.finish();
}
};
}
Aggregations