Search in sources :

Example 61 with ProcessCanceledException

use of com.intellij.openapi.progress.ProcessCanceledException in project intellij-community by JetBrains.

the class WolfTheProblemSolverImpl method orderVincentToCleanTheCar.

// returns true if car has been cleaned
private boolean orderVincentToCleanTheCar(@NotNull final VirtualFile file, @NotNull final ProgressIndicator progressIndicator) throws ProcessCanceledException {
    if (!isToBeHighlighted(file)) {
        clearProblems(file);
        // file is going to be red waved no more
        return true;
    }
    if (hasSyntaxErrors(file)) {
        // optimization: it's no use anyway to try clean the file with syntax errors, only changing the file itself can help
        return false;
    }
    if (myProject.isDisposed())
        return false;
    if (willBeHighlightedAnyway(file))
        return false;
    final PsiFile psiFile = PsiManager.getInstance(myProject).findFile(file);
    if (psiFile == null)
        return false;
    final Document document = FileDocumentManager.getInstance().getDocument(file);
    if (document == null)
        return false;
    final AtomicReference<HighlightInfo> error = new AtomicReference<>();
    final AtomicBoolean hasErrorElement = new AtomicBoolean();
    try {
        GeneralHighlightingPass pass = new GeneralHighlightingPass(myProject, psiFile, document, 0, document.getTextLength(), false, new ProperTextRange(0, document.getTextLength()), null, HighlightInfoProcessor.getEmpty()) {

            @Override
            protected HighlightInfoHolder createInfoHolder(@NotNull final PsiFile file) {
                return new HighlightInfoHolder(file) {

                    @Override
                    public boolean add(@Nullable HighlightInfo info) {
                        if (info != null && info.getSeverity() == HighlightSeverity.ERROR) {
                            error.set(info);
                            hasErrorElement.set(myHasErrorElement);
                            throw new ProcessCanceledException();
                        }
                        return super.add(info);
                    }
                };
            }
        };
        pass.collectInformation(progressIndicator);
    } catch (ProcessCanceledException e) {
        if (error.get() != null) {
            ProblemImpl problem = new ProblemImpl(file, error.get(), hasErrorElement.get());
            reportProblems(file, Collections.singleton(problem));
        }
        return false;
    }
    clearProblems(file);
    return true;
}
Also used : AtomicReference(java.util.concurrent.atomic.AtomicReference) Document(com.intellij.openapi.editor.Document) NotNull(org.jetbrains.annotations.NotNull) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HighlightInfoHolder(com.intellij.codeInsight.daemon.impl.analysis.HighlightInfoHolder) Nullable(org.jetbrains.annotations.Nullable) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException)

Example 62 with ProcessCanceledException

use of com.intellij.openapi.progress.ProcessCanceledException in project intellij-community by JetBrains.

the class FindInProjectUtil method addToUsages.

private static int addToUsages(@NotNull Document document, @NotNull Processor<UsageInfo> consumer, @NotNull FindModel findModel, @NotNull final PsiFile psiFile, @NotNull int[] offsetRef, int maxUsages) {
    int count = 0;
    CharSequence text = document.getCharsSequence();
    int textLength = document.getTextLength();
    int offset = offsetRef[0];
    Project project = psiFile.getProject();
    FindManager findManager = FindManager.getInstance(project);
    while (offset < textLength) {
        FindResult result = findManager.findString(text, offset, findModel, psiFile.getVirtualFile());
        if (!result.isStringFound())
            break;
        final int prevOffset = offset;
        offset = result.getEndOffset();
        if (prevOffset == offset) {
            // for regular expr the size of the match could be zero -> could be infinite loop in finding usages!
            ++offset;
        }
        final SearchScope customScope = findModel.getCustomScope();
        if (customScope instanceof LocalSearchScope) {
            final TextRange range = new TextRange(result.getStartOffset(), result.getEndOffset());
            if (!((LocalSearchScope) customScope).containsRange(psiFile, range))
                continue;
        }
        UsageInfo info = new FindResultUsageInfo(findManager, psiFile, prevOffset, findModel, result);
        if (!consumer.process(info)) {
            throw new ProcessCanceledException();
        }
        count++;
        if (maxUsages > 0 && count >= maxUsages) {
            break;
        }
    }
    offsetRef[0] = offset;
    return count;
}
Also used : Project(com.intellij.openapi.project.Project) TextRange(com.intellij.openapi.util.TextRange) UsageInfo(com.intellij.usageView.UsageInfo) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException)

Example 63 with ProcessCanceledException

use of com.intellij.openapi.progress.ProcessCanceledException in project intellij-community by JetBrains.

the class SearchResults method findInRange.

private void findInRange(TextRange r, Editor editor, FindModel findModel, ArrayList<FindResult> results) {
    VirtualFile virtualFile = FileDocumentManager.getInstance().getFile(editor.getDocument());
    CharSequence charSequence = editor.getDocument().getCharsSequence();
    int offset = r.getStartOffset();
    int maxOffset = Math.min(r.getEndOffset(), charSequence.length());
    FindManager findManager = FindManager.getInstance(getProject());
    while (true) {
        FindResult result;
        try {
            CharSequence bombedCharSequence = StringUtil.newBombedCharSequence(charSequence, 3000);
            result = findManager.findString(bombedCharSequence, offset, findModel, virtualFile);
        } catch (PatternSyntaxException | ProcessCanceledException e) {
            result = null;
        }
        if (result == null || !result.isStringFound())
            break;
        int newOffset = result.getEndOffset();
        if (result.getEndOffset() > maxOffset)
            break;
        if (offset == newOffset) {
            if (offset < maxOffset - 1) {
                offset++;
            } else {
                results.add(result);
                break;
            }
        } else {
            offset = newOffset;
        }
        results.add(result);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FindManager(com.intellij.find.FindManager) FindResult(com.intellij.find.FindResult) PatternSyntaxException(java.util.regex.PatternSyntaxException) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException)

Example 64 with ProcessCanceledException

use of com.intellij.openapi.progress.ProcessCanceledException in project intellij-community by JetBrains.

the class AbstractNewProjectStep method doGenerateProject.

public static Project doGenerateProject(@Nullable final Project projectToClose, @NotNull final String locationString, @Nullable final DirectoryProjectGenerator generator, @NotNull final Function<VirtualFile, Object> settingsComputable) {
    final File location = new File(FileUtil.toSystemDependentName(locationString));
    if (!location.exists() && !location.mkdirs()) {
        String message = ActionsBundle.message("action.NewDirectoryProject.cannot.create.dir", location.getAbsolutePath());
        Messages.showErrorDialog(projectToClose, message, ActionsBundle.message("action.NewDirectoryProject.title"));
        return null;
    }
    final VirtualFile baseDir = ApplicationManager.getApplication().runWriteAction((Computable<VirtualFile>) () -> LocalFileSystem.getInstance().refreshAndFindFileByIoFile(location));
    if (baseDir == null) {
        LOG.error("Couldn't find '" + location + "' in VFS");
        return null;
    }
    VfsUtil.markDirtyAndRefresh(false, true, true, baseDir);
    if (baseDir.getChildren().length > 0) {
        String message = ActionsBundle.message("action.NewDirectoryProject.not.empty", location.getAbsolutePath());
        int rc = Messages.showYesNoDialog(projectToClose, message, ActionsBundle.message("action.NewDirectoryProject.title"), Messages.getQuestionIcon());
        if (rc == Messages.YES) {
            return PlatformProjectOpenProcessor.getInstance().doOpenProject(baseDir, null, false);
        }
    }
    String generatorName = generator == null ? "empty" : ConvertUsagesUtil.ensureProperKey(generator.getName());
    UsageTrigger.trigger("AbstractNewProjectStep." + generatorName);
    Object settings = null;
    if (generator != null) {
        try {
            settings = settingsComputable.fun(baseDir);
        } catch (ProcessCanceledException e) {
            return null;
        }
    }
    RecentProjectsManager.getInstance().setLastProjectCreationLocation(location.getParent());
    ProjectOpenedCallback callback = null;
    if (generator instanceof TemplateProjectDirectoryGenerator) {
        ((TemplateProjectDirectoryGenerator) generator).generateProject(baseDir.getName(), locationString);
    } else {
        final Object finalSettings = settings;
        callback = (p, module) -> {
            if (generator != null) {
                generator.generateProject(p, baseDir, finalSettings, module);
            }
        };
    }
    EnumSet<PlatformProjectOpenProcessor.Option> options = EnumSet.noneOf(PlatformProjectOpenProcessor.Option.class);
    return PlatformProjectOpenProcessor.doOpenProject(baseDir, projectToClose, -1, callback, options);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PlatformProjectOpenProcessor(com.intellij.platform.PlatformProjectOpenProcessor) TemplateProjectDirectoryGenerator(com.intellij.platform.templates.TemplateProjectDirectoryGenerator) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) ProjectOpenedCallback(com.intellij.projectImport.ProjectOpenedCallback) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException)

Example 65 with ProcessCanceledException

use of com.intellij.openapi.progress.ProcessCanceledException in project intellij-community by JetBrains.

the class ChangeSignatureDialogBase method createOptionsPanel.

protected JComponent createOptionsPanel() {
    final JPanel panel = new JPanel(new BorderLayout());
    if (myAllowDelegation) {
        myDelegationPanel = createDelegationPanel();
        panel.add(myDelegationPanel, BorderLayout.WEST);
    }
    myPropagateParamChangesButton = new AnActionButton(RefactoringBundle.message("changeSignature.propagate.parameters.title"), null, AllIcons.Hierarchy.Caller) {

        @Override
        public void actionPerformed(AnActionEvent e) {
            final Ref<CallerChooserBase<Method>> chooser = new Ref<>();
            Consumer<Set<Method>> callback = callers -> {
                myMethodsToPropagateParameters = callers;
                myParameterPropagationTreeToReuse = chooser.get().getTree();
            };
            try {
                String message = RefactoringBundle.message("changeSignature.parameter.caller.chooser");
                chooser.set(createCallerChooser(message, myParameterPropagationTreeToReuse, callback));
            } catch (ProcessCanceledException ex) {
                // user cancelled initial callers search, don't show dialog
                return;
            }
            chooser.get().show();
        }
    };
    final JPanel result = new JPanel(new VerticalFlowLayout(VerticalFlowLayout.TOP));
    result.add(panel);
    return result;
}
Also used : Ref(com.intellij.openapi.util.Ref) Consumer(com.intellij.util.Consumer) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) VerticalFlowLayout(com.intellij.openapi.ui.VerticalFlowLayout)

Aggregations

ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)175 NotNull (org.jetbrains.annotations.NotNull)45 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)41 VirtualFile (com.intellij.openapi.vfs.VirtualFile)38 Project (com.intellij.openapi.project.Project)28 Nullable (org.jetbrains.annotations.Nullable)23 IOException (java.io.IOException)20 Task (com.intellij.openapi.progress.Task)16 File (java.io.File)16 Document (com.intellij.openapi.editor.Document)14 Ref (com.intellij.openapi.util.Ref)13 PsiFile (com.intellij.psi.PsiFile)12 IndexNotReadyException (com.intellij.openapi.project.IndexNotReadyException)11 Logger (com.intellij.openapi.diagnostic.Logger)10 StringUtil (com.intellij.openapi.util.text.StringUtil)9 ContainerUtil (com.intellij.util.containers.ContainerUtil)9 ArrayList (java.util.ArrayList)9 NonNls (org.jetbrains.annotations.NonNls)9 ProgressManager (com.intellij.openapi.progress.ProgressManager)8 java.util (java.util)8