Search in sources :

Example 1 with SequentialModalProgressTask

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();
        }
    };
}
Also used : WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) LocalHistoryAction(com.intellij.history.LocalHistoryAction) NotNull(org.jetbrains.annotations.NotNull) UsageInfo(com.intellij.usageView.UsageInfo) PsiElement(com.intellij.psi.PsiElement) SequentialModalProgressTask(com.intellij.util.SequentialModalProgressTask) Result(com.intellij.openapi.application.Result)

Example 2 with SequentialModalProgressTask

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);
}
Also used : SequentialModalProgressTask(com.intellij.util.SequentialModalProgressTask)

Example 3 with SequentialModalProgressTask

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();
        }
    };
}
Also used : WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) LocalHistoryAction(com.intellij.history.LocalHistoryAction) NotNull(org.jetbrains.annotations.NotNull) UsageInfo(com.intellij.usageView.UsageInfo) SequentialModalProgressTask(com.intellij.util.SequentialModalProgressTask) Result(com.intellij.openapi.application.Result)

Example 4 with SequentialModalProgressTask

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);
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) SequentialModalProgressTask(com.intellij.util.SequentialModalProgressTask) JavaCodeStyleManager(com.intellij.psi.codeStyle.JavaCodeStyleManager) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator)

Example 5 with SequentialModalProgressTask

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();
        }
    };
}
Also used : WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) VirtualFile(com.intellij.openapi.vfs.VirtualFile) NotNull(org.jetbrains.annotations.NotNull) SequentialModalProgressTask(com.intellij.util.SequentialModalProgressTask) Result(com.intellij.openapi.application.Result) LocalHistoryAction(com.intellij.history.LocalHistoryAction) UsageInfo(com.intellij.usageView.UsageInfo)

Aggregations

SequentialModalProgressTask (com.intellij.util.SequentialModalProgressTask)9 NotNull (org.jetbrains.annotations.NotNull)5 LocalHistoryAction (com.intellij.history.LocalHistoryAction)3 Result (com.intellij.openapi.application.Result)3 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)3 UsageInfo (com.intellij.usageView.UsageInfo)3 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 SequentialTask (com.intellij.util.SequentialTask)2 Module (com.intellij.openapi.module.Module)1 Task (com.intellij.openapi.progress.Task)1 EmptyRunnable (com.intellij.openapi.util.EmptyRunnable)1 PsiElement (com.intellij.psi.PsiElement)1 JavaCodeStyleManager (com.intellij.psi.codeStyle.JavaCodeStyleManager)1 XmlAttribute (com.intellij.psi.xml.XmlAttribute)1 XmlTag (com.intellij.psi.xml.XmlTag)1 LinkedHashMap (java.util.LinkedHashMap)1