use of com.intellij.util.Consumer in project intellij-community by JetBrains.
the class GrMainCompletionProvider method completeReference.
@NotNull
static Runnable completeReference(final CompletionParameters parameters, final GrReferenceElement reference, final JavaCompletionSession inheritorsHolder, final PrefixMatcher matcher, final Consumer<LookupElement> _consumer) {
final Consumer<LookupElement> consumer = new Consumer<LookupElement>() {
final Set<LookupElement> added = ContainerUtil.newHashSet();
@Override
public void consume(LookupElement element) {
if (added.add(element)) {
_consumer.consume(element);
}
}
};
final Map<PsiModifierListOwner, LookupElement> staticMembers = ContainerUtil.newHashMap();
final PsiElement qualifier = reference.getQualifier();
final PsiType qualifierType = GroovyCompletionUtil.getQualifierType(qualifier);
if (reference instanceof GrReferenceExpression && (qualifier instanceof GrExpression || qualifier == null)) {
for (String string : CompleteReferencesWithSameQualifier.getVariantsWithSameQualifier((GrReferenceExpression) reference, matcher, (GrExpression) qualifier)) {
consumer.consume(LookupElementBuilder.create(string).withItemTextUnderlined(true));
}
if (parameters.getInvocationCount() < 2 && qualifier != null && qualifierType == null && !(qualifier instanceof GrReferenceExpression && ((GrReferenceExpression) qualifier).resolve() instanceof PsiPackage)) {
if (parameters.getInvocationCount() == 1) {
showInfo();
}
return EmptyRunnable.INSTANCE;
}
}
final List<LookupElement> zeroPriority = ContainerUtil.newArrayList();
PsiClass qualifierClass = com.intellij.psi.util.PsiUtil.resolveClassInClassTypeOnly(qualifierType);
final boolean honorExcludes = qualifierClass == null || !JavaCompletionUtil.isInExcludedPackage(qualifierClass, false);
GroovyCompletionUtil.processVariants(reference, matcher, parameters, lookupElement -> {
Object object = lookupElement.getObject();
if (object instanceof GroovyResolveResult) {
object = ((GroovyResolveResult) object).getElement();
}
if (isLightElementDeclaredDuringCompletion(object)) {
return;
}
if (!(lookupElement instanceof LookupElementBuilder) && inheritorsHolder.alreadyProcessed(lookupElement)) {
return;
}
if (honorExcludes && object instanceof PsiMember && JavaCompletionUtil.isInExcludedPackage((PsiMember) object, true)) {
return;
}
if (!(object instanceof PsiClass)) {
int priority = assignPriority(lookupElement, qualifierType);
lookupElement = JavaCompletionUtil.highlightIfNeeded(qualifierType, PrioritizedLookupElement.withPriority(lookupElement, priority), object, reference);
}
if ((object instanceof PsiMethod || object instanceof PsiField) && ((PsiModifierListOwner) object).hasModifierProperty(PsiModifier.STATIC)) {
if (lookupElement.getLookupString().equals(((PsiMember) object).getName())) {
staticMembers.put(CompletionUtil.getOriginalOrSelf((PsiModifierListOwner) object), lookupElement);
}
}
PrioritizedLookupElement prio = lookupElement.as(PrioritizedLookupElement.CLASS_CONDITION_KEY);
if (prio == null || prio.getPriority() == 0) {
zeroPriority.add(lookupElement);
} else {
consumer.consume(lookupElement);
}
});
for (LookupElement element : zeroPriority) {
consumer.consume(element);
}
if (qualifier == null) {
return addStaticMembers(parameters, matcher, staticMembers, consumer);
}
return EmptyRunnable.INSTANCE;
}
use of com.intellij.util.Consumer in project intellij-community by JetBrains.
the class SvnHistoryProvider method reportAppendableHistory.
public void reportAppendableHistory(FilePath path, final VcsAppendableHistorySessionPartner partner, @Nullable final SVNRevision from, @Nullable final SVNRevision to, final int limit, SVNRevision peg, final boolean forceBackwards) throws VcsException {
FilePath committedPath = path;
Change change = ChangeListManager.getInstance(myVcs.getProject()).getChange(path);
if (change != null) {
final ContentRevision beforeRevision = change.getBeforeRevision();
final ContentRevision afterRevision = change.getAfterRevision();
if (beforeRevision != null && afterRevision != null && !beforeRevision.getFile().equals(afterRevision.getFile()) && afterRevision.getFile().equals(path)) {
committedPath = beforeRevision.getFile();
}
// revision can be VcsRevisionNumber.NULL
if (peg == null && change.getBeforeRevision() != null && change.getBeforeRevision().getRevisionNumber() instanceof SvnRevisionNumber) {
peg = ((SvnRevisionNumber) change.getBeforeRevision().getRevisionNumber()).getRevision();
}
}
boolean showMergeSources = myVcs.getSvnConfiguration().isShowMergeSourcesInAnnotate();
final LogLoader logLoader;
if (path.isNonLocal()) {
logLoader = new RepositoryLoader(myVcs, committedPath, from, to, limit, peg, forceBackwards, showMergeSources);
} else {
logLoader = new LocalLoader(myVcs, committedPath, from, to, limit, peg, showMergeSources);
}
try {
logLoader.preliminary();
} catch (SVNException e) {
throw new VcsException(e);
}
logLoader.check();
if (showMergeSources) {
logLoader.initSupports15();
}
final SvnHistorySession historySession = new SvnHistorySession(myVcs, Collections.emptyList(), committedPath, showMergeSources && Boolean.TRUE.equals(logLoader.mySupport15), null, false, !path.isNonLocal());
final Ref<Boolean> sessionReported = new Ref<>();
final ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
if (indicator != null) {
indicator.setText(SvnBundle.message("progress.text2.collecting.history", path.getName()));
}
final Consumer<VcsFileRevision> consumer = vcsFileRevision -> {
if (!Boolean.TRUE.equals(sessionReported.get())) {
partner.reportCreatedEmptySession(historySession);
sessionReported.set(true);
}
partner.acceptRevision(vcsFileRevision);
};
logLoader.setConsumer(consumer);
logLoader.load();
logLoader.check();
}
use of com.intellij.util.Consumer in project smali by JesusFreke.
the class ErrorReporter method submit.
@Override
public boolean submit(IdeaLoggingEvent[] events, String additionalInfo, Component parentComponent, final Consumer<SubmittedReportInfo> consumer) {
IdeaLoggingEvent event = events[0];
ErrorBean bean = new ErrorBean(event.getThrowable(), IdeaLogger.ourLastActionId);
final DataContext dataContext = DataManager.getInstance().getDataContext(parentComponent);
bean.setDescription(additionalInfo);
bean.setMessage(event.getMessage());
Throwable throwable = event.getThrowable();
if (throwable != null) {
final PluginId pluginId = IdeErrorsDialog.findPluginId(throwable);
if (pluginId != null) {
final IdeaPluginDescriptor ideaPluginDescriptor = PluginManager.getPlugin(pluginId);
if (ideaPluginDescriptor != null && !ideaPluginDescriptor.isBundled()) {
bean.setPluginName(ideaPluginDescriptor.getName());
bean.setPluginVersion(ideaPluginDescriptor.getVersion());
}
}
}
Object data = event.getData();
if (data instanceof LogMessageEx) {
bean.setAttachments(((LogMessageEx) data).getAttachments());
}
Map<String, String> reportValues = ITNProxy.createParameters(bean);
final Project project = CommonDataKeys.PROJECT.getData(dataContext);
Consumer<String> successCallback = new Consumer<String>() {
@Override
public void consume(String token) {
final SubmittedReportInfo reportInfo = new SubmittedReportInfo(null, "Issue " + token, SubmittedReportInfo.SubmissionStatus.NEW_ISSUE);
consumer.consume(reportInfo);
ReportMessages.GROUP.createNotification(ReportMessages.ERROR_REPORT, "Submitted", NotificationType.INFORMATION, null).setImportant(false).notify(project);
}
};
Consumer<Exception> errorCallback = new Consumer<Exception>() {
@Override
public void consume(Exception e) {
String message = String.format("<html>There was an error while creating a GitHub issue: %s<br>" + "Please consider manually creating an issue on the " + "<a href=\"https://github.com/JesusFreke/smali/issues\">Smali Issue Tracker</a></html>", e.getMessage());
ReportMessages.GROUP.createNotification(ReportMessages.ERROR_REPORT, message, NotificationType.ERROR, NotificationListener.URL_OPENING_LISTENER).setImportant(false).notify(project);
}
};
GithubFeedbackTask task = new GithubFeedbackTask(project, "Submitting error report", true, reportValues, successCallback, errorCallback);
if (project == null) {
task.run(new EmptyProgressIndicator());
} else {
ProgressManager.getInstance().run(task);
}
return true;
}
use of com.intellij.util.Consumer in project intellij-community by JetBrains.
the class ProjectTaskManagerImpl method run.
@Override
public void run(@NotNull ProjectTaskContext context, @NotNull ProjectTask projectTask, @Nullable ProjectTaskNotification callback) {
List<Pair<ProjectTaskRunner, Collection<? extends ProjectTask>>> toRun = new SmartList<>();
Consumer<Collection<? extends ProjectTask>> taskClassifier = tasks -> {
Map<ProjectTaskRunner, ? extends List<? extends ProjectTask>> toBuild = tasks.stream().collect(Collectors.groupingBy(aTask -> {
for (ProjectTaskRunner runner : getTaskRunners()) {
if (runner.canRun(aTask))
return runner;
}
return myDefaultProjectTaskRunner;
}));
for (Map.Entry<ProjectTaskRunner, ? extends List<? extends ProjectTask>> entry : toBuild.entrySet()) {
toRun.add(Pair.create(entry.getKey(), entry.getValue()));
}
};
visitTasks(projectTask instanceof ProjectTaskList ? (ProjectTaskList) projectTask : Collections.singleton(projectTask), taskClassifier);
if (toRun.isEmpty()) {
sendSuccessNotify(callback);
return;
}
AtomicInteger inProgressCounter = new AtomicInteger(toRun.size());
AtomicInteger errorsCounter = new AtomicInteger();
AtomicInteger warningsCounter = new AtomicInteger();
AtomicBoolean abortedFlag = new AtomicBoolean(false);
ProjectTaskNotification chunkStatusNotification = callback == null ? null : new ProjectTaskNotification() {
@Override
public void finished(@NotNull ProjectTaskResult executionResult) {
int inProgress = inProgressCounter.decrementAndGet();
int allErrors = errorsCounter.addAndGet(executionResult.getErrors());
int allWarnings = warningsCounter.addAndGet(executionResult.getWarnings());
if (executionResult.isAborted()) {
abortedFlag.set(true);
}
if (inProgress == 0) {
callback.finished(new ProjectTaskResult(abortedFlag.get(), allErrors, allWarnings));
}
}
};
toRun.forEach(pair -> {
if (pair.second.isEmpty()) {
sendSuccessNotify(chunkStatusNotification);
} else {
pair.first.run(myProject, context, chunkStatusNotification, pair.second);
}
});
}
use of com.intellij.util.Consumer in project intellij-community by JetBrains.
the class PsiElementListNavigator method navigateOrCreatePopup.
/**
* listUpdaterTask should be started after alarm is initialized so one-item popup won't blink
*/
@Nullable
public static JBPopup navigateOrCreatePopup(@NotNull final NavigatablePsiElement[] targets, final String title, final String findUsagesTitle, final ListCellRenderer listRenderer, @Nullable final ListBackgroundUpdaterTask listUpdaterTask, @NotNull final Consumer<Object[]> consumer) {
if (targets.length == 0)
return null;
if (targets.length == 1 && (listUpdaterTask == null || listUpdaterTask.isFinished())) {
consumer.consume(targets);
return null;
}
final CollectionListModel<NavigatablePsiElement> model = new CollectionListModel<>(targets);
final JBList list = new JBList(model);
HintUpdateSupply.installSimpleHintUpdateSupply(list);
list.setTransferHandler(new TransferHandler() {
@Nullable
@Override
protected Transferable createTransferable(JComponent c) {
final Object[] selectedValues = list.getSelectedValues();
final PsiElement[] copy = new PsiElement[selectedValues.length];
for (int i = 0; i < selectedValues.length; i++) {
copy[i] = (PsiElement) selectedValues[i];
}
return new PsiCopyPasteManager.MyTransferable(copy);
}
@Override
public int getSourceActions(JComponent c) {
return COPY;
}
});
list.setCellRenderer(listRenderer);
list.setFont(EditorUtil.getEditorFont());
final PopupChooserBuilder builder = new PopupChooserBuilder(list);
if (listRenderer instanceof PsiElementListCellRenderer) {
((PsiElementListCellRenderer) listRenderer).installSpeedSearch(builder);
}
PopupChooserBuilder popupChooserBuilder = builder.setTitle(title).setMovable(true).setResizable(true).setItemChoosenCallback(() -> {
int[] ids = list.getSelectedIndices();
if (ids == null || ids.length == 0)
return;
Object[] selectedElements = list.getSelectedValues();
consumer.consume(selectedElements);
}).setCancelCallback(() -> {
HintUpdateSupply.hideHint(list);
if (listUpdaterTask != null) {
listUpdaterTask.cancelTask();
}
return true;
});
final Ref<UsageView> usageView = new Ref<>();
if (findUsagesTitle != null) {
popupChooserBuilder = popupChooserBuilder.setCouldPin(popup -> {
final List<NavigatablePsiElement> items = model.getItems();
usageView.set(FindUtil.showInUsageView(null, items.toArray(new PsiElement[items.size()]), findUsagesTitle, targets[0].getProject()));
popup.cancel();
return false;
});
}
final JBPopup popup = popupChooserBuilder.createPopup();
builder.getScrollPane().setBorder(null);
builder.getScrollPane().setViewportBorder(null);
if (listUpdaterTask != null) {
listUpdaterTask.init((AbstractPopup) popup, list, usageView);
}
return popup;
}
Aggregations