public List<PsiMember> processMembersOfRegisteredClasses(final PrefixMatcher matcher, PairConsumer<PsiMember, PsiClass> consumer) { final ArrayList<PsiMember> result = ContainerUtil.newArrayList(); for (final PsiClass psiClass : myStaticImportedClasses) { for (final PsiMethod method : psiClass.getAllMethods()) { if (matcher.prefixMatches(method.getName())) { if (isStaticallyImportable(method)) { consumer.consume(method, psiClass); } } } for (final PsiField field : psiClass.getAllFields()) { if (matcher.prefixMatches(field. getName())) { if (isStaticallyImportable(field)) { consumer.consume(field, psiClass); } } } } return result; }
protected MembersGetter(StaticMemberProcessor processor, @NotNull final PsiElement place) { myPlace = place; processor.processMembersOfRegisteredClasses(PrefixMatcher.ALWAYS_TRUE, new PairConsumer<PsiMember, PsiClass>() { @Override public void consume(PsiMember member, PsiClass psiClass) { myImportedStatically.add(member); } }); PsiClass current = PsiTreeUtil.getContextOfType(place, PsiClass.class); while (current != null) { current = CompletionUtil.getOriginalOrSelf(current); myPlaceClasses.add(current); current = PsiTreeUtil.getContextOfType(current, PsiClass.class); } PsiMethod eachMethod = PsiTreeUtil.getContextOfType(place, PsiMethod.class); while (eachMethod != null) { eachMethod = CompletionUtil.getOriginalOrSelf(eachMethod); myPlaceMethods.add(eachMethod); eachMethod = PsiTreeUtil.getContextOfType(eachMethod, PsiMethod.class); } }
public BackgroundTaskQueue(@Nullable final Project project, @NotNull String title, final Boolean forcedHeadlessMode) { myMonitor = Boolean.TRUE.equals(Boolean.getBoolean(ourMonitorFlag)) ? new BackgroundTasksMonitor(title) : new PlusMinus.Empty<String>(); final boolean headless = forcedHeadlessMode != null ? forcedHeadlessMode : ApplicationManager.getApplication().isHeadlessEnvironment(); final QueueProcessor.ThreadToUse threadToUse = headless ? QueueProcessor.ThreadToUse.POOLED : QueueProcessor.ThreadToUse.AWT; final PairConsumer<Pair<Task.Backgroundable, Getter<ProgressIndicator>>, Runnable> consumer = headless ? new BackgroundableHeadlessRunner() : new BackgroundableUnderProgressRunner(title, project, myMonitor); myProcessor = new QueueProcessor<Pair<Task.Backgroundable, Getter<ProgressIndicator>>>(consumer, true, threadToUse, new Condition<Object>() { @Override public boolean value(Object o) { if (project == null) return ApplicationManager.getApplication().isDisposed(); if (project.isDefault()) { return project.isDisposed(); } else { return !ApplicationManager.getApplication().isUnitTestMode() && !project.isOpen() || project.isDisposed(); } } }); }
protected AbstractRefreshablePanel(final Project project, final String loadingTitle, final BackgroundTaskQueue queue) { myQueue = queue; myTicket = new Ticket(); myDetailsPanel = new DetailsPanel(); myDetailsPanel.loading(); myDetailsPanel.layout(); myDetailsLoader = new GenericDetailsLoader<Ticket, T>(new Consumer<Ticket>() { @Override public void consume(Ticket ticket) { final Loader loader = new Loader(project, loadingTitle, myTicket.copy()); loader.runSteadily(new Consumer<Task.Backgroundable>() { @Override public void consume(Task.Backgroundable backgroundable) { myQueue.run(backgroundable); } }); } }, new PairConsumer<Ticket, T>() { @Override public void consume(Ticket ticket, T t) { acceptData(t); } }); }
public static boolean completeReference(final CompletionParameters parameters, final CompletionResultSet result) { final CompletionData completionData = getCompletionData(parameters); if (completionData == null) { return false; } final Ref<Boolean> hasVariants = Ref.create(false); processReferences(parameters, result, new PairConsumer<PsiReference, CompletionResultSet>() { @Override public void consume(final PsiReference reference, final CompletionResultSet resultSet) { final Set<LookupElement> lookupSet = new LinkedHashSet<LookupElement>(); completionData.completeReference(reference, lookupSet, parameters.getPosition(), parameters.getOriginalFile()); for (final LookupElement item : lookupSet) { if (resultSet.getPrefixMatcher().prefixMatches(item)) { if (!item.isValid()) { LOG.error(completionData + " has returned an invalid lookup element " + item + " of " + item.getClass() + " in " + parameters.getOriginalFile() + " of " + parameters.getOriginalFile().getClass()); } hasVariants.set(true); resultSet.addElement(item); } } } }); return hasVariants.get().booleanValue(); }
private static void processReference(final CompletionResultSet result, final int startOffset, final PairConsumer<PsiReference, CompletionResultSet> consumer, final PsiReference reference) { PsiElement element = reference.getElement(); final int offsetInElement = startOffset - element.getTextRange().getStartOffset(); if (!ReferenceRange.containsOffsetInElement(reference, offsetInElement)) { return; } TextRange range = reference.getRangeInElement(); try { final String prefix = element.getText().substring(range.getStartOffset(), offsetInElement); consumer.consume(reference, result.withPrefixMatcher(prefix)); } catch (StringIndexOutOfBoundsException e) { LOG.error("Reference=" + reference + "; element=" + element + " of " + element.getClass() + "; range=" + range + "; offset=" + offsetInElement, e); } }
protected ScratchFileServiceImpl(MessageBus messageBus) { myIndex = new LightDirectoryIndex<RootType>(messageBus.connect(), NULL_TYPE) { @Override protected void collectRoots(@NotNull PairConsumer<VirtualFile, RootType> consumer) { LocalFileSystem fileSystem = LocalFileSystem.getInstance(); for (RootType r : RootType.getAllRootIds()) { String root = getRootPath(r); VirtualFile rootFile = fileSystem.findFileByPath(root); if (rootFile != null) { consumer.consume(rootFile, r); } } } }; initFileOpenedListener(messageBus); }
@Override protected void addCompletions(@NotNull CompletionParameters parameters, ProcessingContext context, @NotNull final CompletionResultSet result) { LegacyCompletionContributor.processReferences(parameters, result, new PairConsumer<PsiReference, CompletionResultSet>() { @Override public void consume(PsiReference reference, CompletionResultSet set) { if (reference instanceof TagNameReference) { collectCompletionVariants((TagNameReference)reference, set); } else if (reference instanceof SchemaPrefixReference) { TagNameReference tagNameReference = ((SchemaPrefixReference)reference).getTagNameReference(); if (tagNameReference != null && !tagNameReference.isStartTagFlag()) { set.consume(createClosingTagLookupElement((XmlTag)tagNameReference.getElement(), true, tagNameReference.getNameElement())); } } } }); }
@Override public ReturnResult beforeCheckin(@Nullable CommitExecutor executor, PairConsumer<Object, Object> additionalDataConsumer) { if (emptyCommitMessage()) { return ReturnResult.CANCEL; } if (commitOrCommitAndPush(executor)) { ReturnResult result = checkUserName(); if (result != ReturnResult.COMMIT) { return result; } result = warnAboutCrlfIfNeeded(); if (result != ReturnResult.COMMIT) { return result; } return warnAboutDetachedHeadIfNeeded(); } return ReturnResult.COMMIT; }
@Override public List<CommittedChangeList> showRecentListsForSelection(@NotNull List<CommittedChangeList> list, @NotNull String mergeTitle, @NotNull MergeChecker mergeChecker, @NotNull PairConsumer<Long, MergeDialogI> loader, boolean everyThingLoaded) { final ToBeMergedDialog dialog = new ToBeMergedDialog(myProject, list, mergeTitle, mergeChecker, loader); if (everyThingLoaded) { dialog.setEverythingLoaded(true); } dialog.show(); if (DialogWrapper.OK_EXIT_CODE == dialog.getExitCode()) { return dialog.getSelected(); } return null; }
@NotNull private PairConsumer<Long, MergeDialogI> createMoreChangeListsLoader() { return new PairConsumer<Long, MergeDialogI>() { @Override public void consume(@NotNull Long bunchSize, @NotNull MergeDialogI dialog) { LoadRecentBranchRevisions loader = new LoadRecentBranchRevisions(myMergeContext, dialog.getLastNumber(), bunchSize.intValue()); TaskDescriptor updater = createUpdateDialogTask(dialog, loader); Continuation fragmented = Continuation.createFragmented(myMergeContext.getProject(), true); fragmented.addExceptionHandler(VcsException.class, new Consumer<VcsException>() { @Override public void consume(VcsException e) { PopupUtil.showBalloonForActiveComponent(e.getMessage() == null ? e.getClass().getName() : e.getMessage(), MessageType.ERROR); } }); fragmented.run(loader, updater); } }; }
@NotNull private List<Pair<SvnChangeList, LogHierarchyNode>> getChangeListsBefore(long revision) throws VcsException { ChangeBrowserSettings settings = new ChangeBrowserSettings(); if (revision > 0) { settings.CHANGE_BEFORE = String.valueOf(revision); settings.USE_CHANGE_BEFORE_FILTER = true; } final ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator(); ProgressManager.progress2( SvnBundle.message("progress.text2.collecting.history", myMergeContext.getSourceUrl() + (revision > 0 ? ("@" + revision) : ""))); final List<Pair<SvnChangeList, LogHierarchyNode>> result = ContainerUtil.newArrayList(); ((SvnCommittedChangesProvider)myMergeContext.getVcs().getCommittedChangesProvider()) .getCommittedChangesWithMergedRevisons(settings, new SvnRepositoryLocation(myMergeContext.getSourceUrl()), myBunchSize + (revision > 0 ? 2 : 1), new PairConsumer<SvnChangeList, LogHierarchyNode>() { public void consume(SvnChangeList svnList, LogHierarchyNode tree) { indicator.setText2( SvnBundle.message("progress.text2.processing.revision", svnList.getNumber())); result.add(Pair.create(svnList, tree)); } }); return result; }
@Override protected Collection<String> getKeyVariants(@NotNull GrExpression qualifier, @Nullable PsiElement resolve) { Pair<ConfigSlurperSupport.PropertiesProvider, List<String>> info = getInfo(qualifier, resolve); if (info == null) return Collections.emptyList(); final Set<String> res = new HashSet<String>(); info.first.collectVariants(info.second, new PairConsumer<String, Boolean>() { @Override public void consume(String variant, Boolean isFinal) { res.add(variant); } }); return res; }
@Override public PsiType getValueType(@NotNull GrExpression qualifier, @Nullable PsiElement resolve, @NotNull final String key) { Pair<ConfigSlurperSupport.PropertiesProvider, List<String>> info = getInfo(qualifier, resolve); if (info == null) return null; final Ref<Boolean> res = new Ref<Boolean>(); info.first.collectVariants(info.second, new PairConsumer<String, Boolean>() { @Override public void consume(String variant, Boolean isFinal) { if (variant.equals(key)) { res.set(isFinal); } else if (variant.startsWith(key) && variant.length() > key.length() && variant.charAt(key.length()) == '.') { res.set(false); } } }); if (res.get() != null && !res.get()) { return JavaPsiFacade.getElementFactory(qualifier.getProject()).createTypeByFQClassName(GroovyCommonClassNames.GROOVY_UTIL_CONFIG_OBJECT, qualifier.getResolveScope()); } return null; }
public static boolean completeReference(final CompletionParameters parameters, final CompletionResultSet result) { final CompletionData completionData = getCompletionData(parameters); if (completionData == null) { return false; } final Ref<Boolean> hasVariants = Ref.create(false); processReferences(parameters, result, new PairConsumer<PsiReference, CompletionResultSet>() { @Override public void consume(final PsiReference reference, final CompletionResultSet resultSet) { final Set<LookupElement> lookupSet = new LinkedHashSet<LookupElement>(); completionData .completeReference(reference, lookupSet, parameters.getPosition(), parameters.getOriginalFile(), parameters.getOffset()); for (final LookupElement item : lookupSet) { if (resultSet.getPrefixMatcher().prefixMatches(item)) { hasVariants.set(true); resultSet.addElement(item); } } } }); return hasVariants.get().booleanValue(); }
private void createStatusHighlighter() { int line1 = myPatchDeletionRange.start; int line2 = myPatchInsertionRange.end; Color color = getStatusColor(); if (isResolved()) { color = ColorUtil.mix(color, myViewer.getPatchEditor().getGutterComponentEx().getBackground(), 0.6f); } String tooltip = getStatusText(); EditorEx patchEditor = myViewer.getPatchEditor(); Document document = patchEditor.getDocument(); MarkupModelEx markupModel = patchEditor.getMarkupModel(); TextRange textRange = DiffUtil.getLinesRange(document, line1, line2); RangeHighlighter highlighter = markupModel.addRangeHighlighter(textRange.getStartOffset(), textRange.getEndOffset(), HighlighterLayer.LAST, null, HighlighterTargetArea.LINES_IN_RANGE); PairConsumer<Editor, MouseEvent> clickHandler = getResultRange() != null ? (e, event) -> myViewer.scrollToChange(this, Side.RIGHT, false) : null; highlighter.setLineMarkerRenderer(LineStatusMarkerRenderer.createRenderer(line1, line2, color, tooltip, clickHandler)); myHighlighters.add(highlighter); }
private void functionalInterfaceSelected(final PsiType selectedType, final List<PsiMethod> enclosingMethods, final Project project, final Editor editor, final MyExtractMethodProcessor processor, final PsiElement[] elements) { final PairConsumer<PsiMethod, PsiMethod> consumer = new PairConsumer<PsiMethod, PsiMethod>() { @Override public void consume(PsiMethod methodToIntroduceParameter, PsiMethod methodToSearchFor) { introduceWrappedCodeBlockParameter(methodToIntroduceParameter, methodToSearchFor, editor, project, selectedType, processor, elements); } }; chooseMethodToIntroduceParameter(editor, enclosingMethods, consumer); }
public void doTranslate(PairConsumer<Integer, Integer> consumer) { final JBTabsPosition pos = myTabs.getTabsPosition(); int dX = 0; int dXs = 0; int dY = 0; int dYs = 0; int selected = getSelectedOffset(); int plain = getNonSelectedOffset(); switch (pos) { case bottom: dY = -plain; dYs = -selected; break; case left: dX = plain; dXs = selected; break; case right: dX = -plain; dXs = -selected; break; case top: dY = plain; dYs = selected; break; } if (!myTabs.isDropTarget(myInfo)) { if (myTabs.getSelectedInfo() != myInfo) { consumer.consume(dX, dY); } else { consumer.consume(dXs, dYs); } } }
@NotNull private static <T> PairConsumer<T, Runnable> wrappingProcessor(@NotNull final Consumer<T> processor) { return new PairConsumer<T, Runnable>() { @Override public void consume(final T item, Runnable runnable) { runSafely(new Runnable() { @Override public void run() { processor.consume(item); } }); runnable.run(); } }; }
/** * Constructs a QueueProcessor with the given processor and autostart setting. * By default QueueProcessor starts processing when it receives the first element. Pass <code>false</code> to alternate its behavior. * * @param processor processor of queue elements. * @param autostart if <code>true</code> (which is by default), the queue will be processed immediately when it receives the first element. * If <code>false</code>, then it will wait for the {@link #start()} command. * After QueueProcessor has started once, autostart setting doesn't matter anymore: all other elements will be processed immediately. */ public QueueProcessor(@NotNull PairConsumer<T, Runnable> processor, boolean autostart, @NotNull ThreadToUse threadToUse, @NotNull Condition<?> deathCondition) { myProcessor = processor; myStarted = autostart; myThreadToUse = threadToUse; myDeathCondition = deathCondition; }
public static void findChildRangeDuplicates(PsiElement first, PsiElement last, final List<Couple<PsiElement>> result, PsiElement scope) { findChildRangeDuplicates(first, last, scope, new PairConsumer<PsiElement, PsiElement>() { @Override public void consume(final PsiElement start, final PsiElement end) { result.add(Couple.of(start, end)); } }); }
private static void addRangeDuplicates(final PsiElement scope, final PsiElement first, final PsiElement last, final PairConsumer<PsiElement, PsiElement> result) { final PsiElement[] children = getFilteredChildren(scope, null, true); NextChild: for (int i = 0; i < children.length;) { PsiElement child = children[i]; if (child != first) { int j = i; PsiElement next = first; do { if (!areElementsEquivalent(children[j], next)) break; j++; if (next == last) { result.consume(child, children[j - 1]); i = j + 1; continue NextChild; } next = PsiTreeUtil.skipSiblingsForward(next, PsiWhiteSpace.class); } while (true); if (i == j) { addRangeDuplicates(child, first, last, result); } } i++; } }
@NotNull public AsyncResult<T> doWhenRejected(@NotNull final PairConsumer<T, String> consumer) { doWhenRejected(new Runnable() { @Override public void run() { consumer.consume(myResult, myError); } }); return this; }
@NotNull public final ActionCallback doWhenProcessed(@NotNull final Consumer<T> consumer) { doWhenDone(consumer); doWhenRejected(new PairConsumer<T, String>() { @Override public void consume(T result, String error) { consumer.consume(result); } }); return this; }
public void process(final Iterable<Data> data, final PairConsumer<Data, Area> consumer) { myDataIterator = data.iterator(); if (! myDataIterator.hasNext() || noMoreAreas()) return; dataStep(); initArea(); while (! noMoreAreas()) { final boolean intersects = myAreaRange.intersects(myDataRange); if (intersects) { consumer.consume(myCurData, myCurArea); } // take next if (! myDataIterator.hasNext() && noMoreAreas()) break; if (! myDataIterator.hasNext()) { areaStep(); continue; } if (noMoreAreas()) { dataStep(); continue; } if (myDataRange.getEndOffset() < myAreaRange.getEndOffset()) { dataStep(); } else { areaStep(); } } }
@Override public ReturnResult beforeCheckin(@Nullable CommitExecutor executor, PairConsumer<Object, Object> additionalDataConsumer) { if (! myConfiguration.CHECK_NEW_TODO) return ReturnResult.COMMIT; if (DumbService.getInstance(myProject).isDumb()) { final String todoName = VcsBundle.message("before.checkin.new.todo.check.title"); if (Messages.showOkCancelDialog(myProject, todoName + " can't be performed while " + ApplicationNamesInfo.getInstance().getFullProductName() + " updates the indices in background.\n" + "You can commit the changes without running checks, or you can wait until indices are built.", todoName + " is not possible right now", "&Wait", "&Commit", null) == Messages.OK) { return ReturnResult.CANCEL; } return ReturnResult.COMMIT; } final Collection<Change> changes = myCheckinProjectPanel.getSelectedChanges(); final TodoCheckinHandlerWorker worker = new TodoCheckinHandlerWorker(myProject, changes, myTodoFilter, true); final Ref<Boolean> completed = Ref.create(Boolean.FALSE); ProgressManager.getInstance().run(new Task.Modal(myProject, "Looking for new and edited TODO items...", true) { @Override public void run(@NotNull ProgressIndicator indicator) { indicator.setIndeterminate(true); worker.execute(); } @Override public void onSuccess() { completed.set(Boolean.TRUE); } }); if (completed.get() && (worker.getAddedOrEditedTodos().isEmpty() && worker.getInChangedTodos().isEmpty() && worker.getSkipped().isEmpty())) return ReturnResult.COMMIT; if (!completed.get()) return ReturnResult.CANCEL; return showResults(worker, executor); }
public SameThreadMode(final boolean cancelable, @Nullable final String title2, final int timeout, @NotNull final PairConsumer<ExecutionMode, String> timeoutCallback ) { super(cancelable, null, title2, false, false, null); myTimeout = timeout; myTimeoutCallback = timeoutCallback; }