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;
}
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;
}
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);
}
}
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);
}
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;
}
Aggregations