use of com.intellij.util.Consumer in project intellij-elixir by KronicDeth.
the class Submitter method successCallback.
@NotNull
private static Consumer<Boolean> successCallback(@Nullable final Project project, @NotNull final Consumer<SubmittedReportInfo> consumer) {
return new Consumer<Boolean>() {
@Override
public void consume(Boolean opened) {
String url = null;
String linkText = null;
//noinspection ConstantConditions
final SubmittedReportInfo reportInfo = new SubmittedReportInfo(url, linkText, SubmittedReportInfo.SubmissionStatus.NEW_ISSUE);
consumer.consume(reportInfo);
// pseudo-named-arguments
NotificationListener notificationListener = null;
//noinspection ConstantConditions
ReportMessages.GROUP.createNotification(ReportMessages.ERROR_REPORT, "Submitted", NotificationType.INFORMATION, notificationListener).setImportant(false).notify(project);
}
};
}
use of com.intellij.util.Consumer in project intellij-community by JetBrains.
the class BaseSpellChecker method doLoadDictionaryAsync.
private void doLoadDictionaryAsync(Loader loader, Consumer<Dictionary> consumer) {
StartupManager.getInstance(myProject).runWhenProjectIsInitialized(() -> {
LOG.debug("Loading " + loader.getName());
Application app = ApplicationManager.getApplication();
app.executeOnPooledThread(() -> {
if (app.isDisposed())
return;
CompressedDictionary dictionary = CompressedDictionary.create(loader, transform);
LOG.debug(loader.getName() + " loaded!");
consumer.consume(dictionary);
while (!myDictionariesToLoad.isEmpty()) {
if (app.isDisposed())
return;
Pair<Loader, Consumer<Dictionary>> nextDictionary = myDictionariesToLoad.remove(0);
Loader nextDictionaryLoader = nextDictionary.getFirst();
dictionary = CompressedDictionary.create(nextDictionaryLoader, transform);
LOG.debug(nextDictionaryLoader.getName() + " loaded!");
nextDictionary.getSecond().consume(dictionary);
}
LOG.debug("Loading finished, restarting daemon...");
myLoadingDictionaries.set(false);
UIUtil.invokeLaterIfNeeded(() -> {
if (app.isDisposed())
return;
for (final Project project : ProjectManager.getInstance().getOpenProjects()) {
if (project.isInitialized() && project.isOpen() && !project.isDefault()) {
DaemonCodeAnalyzer instance = DaemonCodeAnalyzer.getInstance(project);
if (instance != null)
instance.restart();
}
}
});
});
});
}
use of com.intellij.util.Consumer in project intellij-community by JetBrains.
the class MvcModuleStructureUtil method addJarDirectory.
@Nullable
public static Consumer<ModifiableRootModel> addJarDirectory(VirtualFile root, Module module, final String libName) {
final VirtualFile libDir = root.findFileByRelativePath("lib");
if (libDir == null || !libDir.isDirectory() || ProjectRootManager.getInstance(module.getProject()).getFileIndex().isExcluded(libDir)) {
return null;
}
final Library library = findUserLibrary(module, libName);
if (library != null && library.isJarDirectory(libDir.getUrl())) {
return null;
}
return model -> {
Library.ModifiableModel libModel = modifyDefaultLibrary(model, libName);
libModel.addJarDirectory(libDir, false);
libModel.commit();
};
}
use of com.intellij.util.Consumer in project intellij-community by JetBrains.
the class GroovySmartCompletionContributor method addExpectedClassMembers.
static void addExpectedClassMembers(CompletionParameters params, final CompletionResultSet result) {
for (final TypeConstraint info : getExpectedTypeInfos(params)) {
Consumer<LookupElement> consumer = element -> result.addElement(element);
PsiType type = info.getType();
PsiType defType = info.getDefaultType();
boolean searchInheritors = params.getInvocationCount() > 1;
if (type instanceof PsiClassType) {
new GroovyMembersGetter((PsiClassType) type, params).processMembers(searchInheritors, consumer);
}
if (!defType.equals(type) && defType instanceof PsiClassType) {
new GroovyMembersGetter((PsiClassType) defType, params).processMembers(searchInheritors, consumer);
}
}
}
use of com.intellij.util.Consumer in project intellij-community by JetBrains.
the class MavenAttachSourcesProvider method getActions.
@Override
@NotNull
public Collection<AttachSourcesAction> getActions(final List<LibraryOrderEntry> orderEntries, final PsiFile psiFile) {
Collection<MavenProject> projects = getMavenProjects(psiFile);
if (projects.isEmpty())
return Collections.emptyList();
if (findArtifacts(projects, orderEntries).isEmpty())
return Collections.emptyList();
return Collections.singleton(new AttachSourcesAction() {
@Override
public String getName() {
return ProjectBundle.message("maven.action.download.sources");
}
@Override
public String getBusyText() {
return ProjectBundle.message("maven.action.download.sources.busy.text");
}
@Override
public ActionCallback perform(List<LibraryOrderEntry> orderEntries) {
// may have been changed by this time...
Collection<MavenProject> mavenProjects = getMavenProjects(psiFile);
if (mavenProjects.isEmpty()) {
return ActionCallback.REJECTED;
}
MavenProjectsManager manager = MavenProjectsManager.getInstance(psiFile.getProject());
Collection<MavenArtifact> artifacts = findArtifacts(mavenProjects, orderEntries);
if (artifacts.isEmpty())
return ActionCallback.REJECTED;
final AsyncResult<MavenArtifactDownloader.DownloadResult> result = new AsyncResult<>();
manager.scheduleArtifactsDownloading(mavenProjects, artifacts, true, false, result);
final ActionCallback resultWrapper = new ActionCallback();
result.doWhenDone(new Consumer<MavenArtifactDownloader.DownloadResult>() {
@Override
public void consume(MavenArtifactDownloader.DownloadResult downloadResult) {
if (!downloadResult.unresolvedSources.isEmpty()) {
final StringBuilder message = new StringBuilder();
message.append("<html>Sources not found for:");
int count = 0;
for (MavenId each : downloadResult.unresolvedSources) {
if (count++ > 5) {
message.append("<br>and more...");
break;
}
message.append("<br>").append(each.getDisplayString());
}
message.append("</html>");
Notifications.Bus.notify(new Notification(MavenUtil.MAVEN_NOTIFICATION_GROUP, "Cannot download sources", message.toString(), NotificationType.WARNING), psiFile.getProject());
}
if (downloadResult.resolvedSources.isEmpty()) {
resultWrapper.setRejected();
} else {
resultWrapper.setDone();
}
}
});
return resultWrapper;
}
});
}
Aggregations