use of com.intellij.util.Processor in project intellij-community by JetBrains.
the class QueryExecutorBase method execute.
@Override
public final boolean execute(@NotNull final Params queryParameters, @NotNull final Processor<Result> consumer) {
final AtomicBoolean toContinue = new AtomicBoolean(true);
final Processor<Result> wrapper = result -> {
if (!toContinue.get()) {
return false;
}
if (!consumer.process(result)) {
toContinue.set(false);
return false;
}
return true;
};
if (myRequireReadAction && !ApplicationManager.getApplication().isReadAccessAllowed()) {
Runnable runnable = () -> processQuery(queryParameters, wrapper);
if (!DumbService.isDumbAware(this)) {
Project project = queryParameters instanceof DumbAwareSearchParameters ? ((DumbAwareSearchParameters) queryParameters).getProject() : null;
if (project != null) {
DumbService.getInstance(project).runReadActionInSmartMode(runnable);
return toContinue.get();
}
}
ApplicationManager.getApplication().runReadAction(runnable);
} else {
processQuery(queryParameters, wrapper);
}
return toContinue.get();
}
use of com.intellij.util.Processor in project intellij-community by JetBrains.
the class ChangeMethodSignatureFromUsageFix method performChange.
public static List<ParameterInfoImpl> performChange(final Project project, final Editor editor, final PsiFile file, final PsiMethod method, final int minUsagesNumber, final ParameterInfoImpl[] newParametersInfo, final boolean changeAllUsages, final boolean allowDelegation) {
if (!FileModificationService.getInstance().prepareFileForWrite(method.getContainingFile()))
return null;
final FindUsagesManager findUsagesManager = ((FindManagerImpl) FindManager.getInstance(project)).getFindUsagesManager();
final FindUsagesHandler handler = findUsagesManager.getFindUsagesHandler(method, false);
//on failure or cancel (e.g. cancel of super methods dialog)
if (handler == null)
return null;
final JavaMethodFindUsagesOptions options = new JavaMethodFindUsagesOptions(project);
options.isImplementingMethods = true;
options.isOverridingMethods = true;
options.isUsages = true;
options.isSearchForTextOccurrences = false;
final int[] usagesFound = new int[1];
Runnable runnable = () -> {
Processor<UsageInfo> processor = t -> ++usagesFound[0] < minUsagesNumber;
handler.processElementUsages(method, processor, options);
};
String progressTitle = QuickFixBundle.message("searching.for.usages.progress.title");
if (!ProgressManager.getInstance().runProcessWithProgressSynchronously(runnable, progressTitle, true, project))
return null;
if (ApplicationManager.getApplication().isUnitTestMode() || usagesFound[0] < minUsagesNumber) {
ChangeSignatureProcessor processor = new ChangeSignatureProcessor(project, method, false, null, method.getName(), method.getReturnType(), newParametersInfo) {
@Override
@NotNull
protected UsageInfo[] findUsages() {
return changeAllUsages ? super.findUsages() : UsageInfo.EMPTY_ARRAY;
}
@Override
protected void performRefactoring(@NotNull UsageInfo[] usages) {
CommandProcessor.getInstance().setCurrentCommandName(getCommandName());
super.performRefactoring(usages);
}
};
processor.run();
ApplicationManager.getApplication().runWriteAction(() -> UndoUtil.markPsiFileForUndo(file));
return Arrays.asList(newParametersInfo);
} else {
final List<ParameterInfoImpl> parameterInfos = newParametersInfo != null ? new ArrayList<>(Arrays.asList(newParametersInfo)) : new ArrayList<>();
final PsiReferenceExpression refExpr = JavaTargetElementEvaluator.findReferenceExpression(editor);
JavaChangeSignatureDialog dialog = JavaChangeSignatureDialog.createAndPreselectNew(project, method, parameterInfos, allowDelegation, refExpr);
dialog.setParameterInfos(parameterInfos);
dialog.show();
return dialog.isOK() ? dialog.getParameters() : null;
}
}
use of com.intellij.util.Processor in project intellij-community by JetBrains.
the class PsiSearchHelperImpl method collectFiles.
private void collectFiles(@NotNull MultiMap<Set<IdIndexEntry>, RequestWithProcessor> singles, @NotNull ProgressIndicator progress, @NotNull final MultiMap<VirtualFile, RequestWithProcessor> intersectionResult, @NotNull final MultiMap<VirtualFile, RequestWithProcessor> restResult) {
for (Map.Entry<Set<IdIndexEntry>, Collection<RequestWithProcessor>> entry : singles.entrySet()) {
final Set<IdIndexEntry> keys = entry.getKey();
if (keys.isEmpty()) {
continue;
}
final Collection<RequestWithProcessor> processors = entry.getValue();
final GlobalSearchScope commonScope = uniteScopes(processors);
final Set<VirtualFile> intersectionWithContainerNameFiles = intersectionWithContainerNameFiles(commonScope, processors, keys);
List<VirtualFile> result = new ArrayList<>();
Processor<VirtualFile> processor = Processors.cancelableCollectProcessor(result);
processFilesContainingAllKeys(myManager.getProject(), commonScope, null, keys, processor);
for (final VirtualFile file : result) {
progress.checkCanceled();
for (final IdIndexEntry indexEntry : keys) {
DumbService.getInstance(myManager.getProject()).runReadActionInSmartMode(() -> FileBasedIndex.getInstance().processValues(IdIndex.NAME, indexEntry, file, (file1, value) -> {
int mask = value.intValue();
for (RequestWithProcessor single : processors) {
final PsiSearchRequest request = single.request;
if ((mask & request.searchContext) != 0 && request.searchScope.contains(file1)) {
MultiMap<VirtualFile, RequestWithProcessor> result1 = intersectionWithContainerNameFiles == null || !intersectionWithContainerNameFiles.contains(file1) ? restResult : intersectionResult;
result1.putValue(file1, single);
}
}
return true;
}, commonScope));
}
}
}
}
use of com.intellij.util.Processor in project intellij-community by JetBrains.
the class MavenDomProjectProcessorUtils method searchManagedPluginUsages.
@NotNull
public static Collection<MavenDomPlugin> searchManagedPluginUsages(@NotNull final MavenDomProjectModel model, @Nullable final String groupId, @NotNull final String artifactId) {
Project project = model.getManager().getProject();
final Set<MavenDomPlugin> usages = new HashSet<>();
Processor<MavenDomProjectModel> collectProcessor = mavenDomProjectModel -> {
for (MavenDomPlugin domPlugin : mavenDomProjectModel.getBuild().getPlugins().getPlugins()) {
if (MavenPluginDomUtil.isPlugin(domPlugin, groupId, artifactId)) {
usages.add(domPlugin);
}
}
return false;
};
processChildrenRecursively(model, collectProcessor, project, new HashSet<>(), true);
return usages;
}
use of com.intellij.util.Processor in project intellij-community by JetBrains.
the class CreateComponentAction method actionPerformed.
protected void actionPerformed(final GuiEditor editor, final List<RadComponent> selection, final AnActionEvent e) {
Processor<ComponentItem> processor = selectedValue -> {
if (selectedValue != null) {
myLastCreatedComponent = selectedValue;
editor.getMainProcessor().startInsertProcessor(selectedValue, getCreateLocation(editor, selection));
}
return true;
};
PaletteListPopupStep step = new PaletteListPopupStep(editor, myLastCreatedComponent, processor, UIDesignerBundle.message("create.component.title"));
final ListPopup listPopup = JBPopupFactory.getInstance().createListPopup(step);
if (selection.size() > 0) {
FormEditingUtil.showPopupUnderComponent(listPopup, selection.get(0));
} else {
listPopup.showInCenterOf(editor.getRootContainer().getDelegee());
}
}
Aggregations