use of com.intellij.util.Consumer in project android by JetBrains.
the class AndroidExtractAsIncludeAction method doRefactorForPsiRange.
@Override
protected void doRefactorForPsiRange(@NotNull final Project project, @NotNull final PsiFile file, @NotNull final PsiElement from, @NotNull final PsiElement to) {
final PsiDirectory dir = file.getContainingDirectory();
if (dir == null) {
return;
}
final AndroidFacet facet = AndroidFacet.getInstance(from);
assert facet != null;
final XmlTag parentTag = PsiTreeUtil.getParentOfType(from, XmlTag.class);
assert parentTag != null;
final List<XmlTag> tagsInRange = collectAllTags(from, to);
assert tagsInRange.size() > 0 : "there is no tag inside the range";
final String fileName = myTestConfig != null ? myTestConfig.myLayoutFileName : null;
final String dirName = dir.getName();
final FolderConfiguration config = dirName.length() > 0 ? FolderConfiguration.getConfig(dirName.split(SdkConstants.RES_QUALIFIER_SEP)) : null;
final String title = "Extract Android Layout";
AsyncResult<DataContext> dataContextAsyncResult = DataManager.getInstance().getDataContextFromFocus();
dataContextAsyncResult.doWhenDone((Consumer<DataContext>) dataContext -> CommandProcessor.getInstance().executeCommand(project, new Runnable() {
@Override
public void run() {
final XmlFile newFile = CreateResourceFileAction.createFileResource(facet, ResourceFolderType.LAYOUT, fileName, "temp_root", config, true, title, null, dataContext);
if (newFile != null) {
ApplicationManager.getApplication().runWriteAction(new Runnable() {
@Override
public void run() {
doRefactor(facet, file, newFile, from, to, parentTag, tagsInRange.size() > 1);
}
});
}
}
}, title, null, UndoConfirmationPolicy.REQUEST_CONFIRMATION));
}
use of com.intellij.util.Consumer in project go-lang-idea-plugin by go-lang-plugin-org.
the class GoRenameQuickFix method invoke.
@Override
public void invoke(@NotNull Project project, @NotNull PsiFile file, @NotNull PsiElement startElement, @NotNull PsiElement endElement) {
if (!FileModificationService.getInstance().preparePsiElementsForWrite(startElement))
return;
Runnable runnable = () -> {
AsyncResult<DataContext> dataContextContainer = DataManager.getInstance().getDataContextFromFocus();
dataContextContainer.doWhenDone(new Consumer<DataContext>() {
@Override
public void consume(DataContext dataContext) {
RenameHandler renameHandler = RenameHandlerRegistry.getInstance().getRenameHandler(dataContext);
if (renameHandler != null) {
renameHandler.invoke(project, new PsiElement[] { startElement }, dataContext);
} else {
RefactoringActionHandler renameRefactoringHandler = RefactoringActionHandlerFactory.getInstance().createRenameHandler();
renameRefactoringHandler.invoke(project, new PsiElement[] { startElement }, dataContext);
}
}
});
};
if (ApplicationManager.getApplication().isUnitTestMode()) {
runnable.run();
} else {
ApplicationManager.getApplication().invokeLater(runnable, project.getDisposed());
}
}
use of com.intellij.util.Consumer in project android by JetBrains.
the class AndroidGradleTestCase method invokeGradle.
@NotNull
private static GradleInvocationResult invokeGradle(@NotNull Project project, @NotNull Consumer<GradleBuildInvoker> gradleInvocationTask) throws InterruptedException {
Ref<GradleInvocationResult> resultRef = new Ref<>();
CountDownLatch latch = new CountDownLatch(1);
GradleBuildInvoker gradleBuildInvoker = GradleBuildInvoker.getInstance(project);
GradleBuildInvoker.AfterGradleInvocationTask task = result -> {
resultRef.set(result);
latch.countDown();
};
gradleBuildInvoker.add(task);
try {
gradleInvocationTask.consume(gradleBuildInvoker);
} finally {
gradleBuildInvoker.remove(task);
}
latch.await();
GradleInvocationResult result = resultRef.get();
assert result != null;
return result;
}
use of com.intellij.util.Consumer in project android by JetBrains.
the class ErrorReporter method submit.
@Override
public boolean submit(@NotNull IdeaLoggingEvent[] events, @Nullable String description, @Nullable Component parentComponent, @NotNull Consumer<SubmittedReportInfo> callback) {
IdeaLoggingEvent event = events[0];
ErrorBean bean = new ErrorBean(event.getThrowable(), IdeaLogger.ourLastActionId);
final DataContext dataContext = DataManager.getInstance().getDataContext(parentComponent);
bean.setDescription(description);
bean.setMessage(event.getMessage());
Throwable t = event.getThrowable();
if (t != null) {
final PluginId pluginId = IdeErrorsDialog.findPluginId(t);
if (pluginId != null) {
final IdeaPluginDescriptor ideaPluginDescriptor = PluginManager.getPlugin(pluginId);
if (ideaPluginDescriptor != null && (!ideaPluginDescriptor.isBundled() || ideaPluginDescriptor.allowBundledUpdate())) {
bean.setPluginName(ideaPluginDescriptor.getName());
bean.setPluginVersion(ideaPluginDescriptor.getVersion());
}
}
}
Object data = event.getData();
// Early escape (and no UI impact) if these are analytics events being pushed from the platform
if (handleAnalyticsReports(t, data)) {
return true;
}
if (data instanceof AbstractMessage) {
bean.setAttachments(((AbstractMessage) data).getIncludedAttachments());
}
final Project project = CommonDataKeys.PROJECT.getData(dataContext);
Consumer<String> successCallback = token -> {
final SubmittedReportInfo reportInfo = new SubmittedReportInfo(null, "Issue " + token, SubmittedReportInfo.SubmissionStatus.NEW_ISSUE);
callback.consume(reportInfo);
ReportMessages.GROUP.createNotification(ReportMessages.ERROR_REPORT, "Submitted", NotificationType.INFORMATION, null).setImportant(false).notify(project);
};
Consumer<Exception> errorCallback = e -> {
String message = AndroidBundle.message("error.report.at.b.android", e.getMessage());
ReportMessages.GROUP.createNotification(ReportMessages.ERROR_REPORT, message, NotificationType.ERROR, NotificationListener.URL_OPENING_LISTENER).setImportant(false).notify(project);
};
Task.Backgroundable feedbackTask;
if (data instanceof ErrorReportCustomizer) {
feedbackTask = ((ErrorReportCustomizer) data).makeReportingTask(project, FEEDBACK_TASK_TITLE, true, bean, successCallback, errorCallback);
} else {
List<Pair<String, String>> kv = IdeaITNProxy.getKeyValuePairs(null, null, bean, IdeaLogger.getOurCompilationTimestamp(), ApplicationManager.getApplication(), (ApplicationInfoEx) ApplicationInfo.getInstance(), ApplicationNamesInfo.getInstance(), UpdateSettings.getInstance());
feedbackTask = new SubmitCrashReportTask(project, FEEDBACK_TASK_TITLE, true, t, pair2map(kv), successCallback, errorCallback);
}
if (project == null) {
feedbackTask.run(new EmptyProgressIndicator());
} else {
ProgressManager.getInstance().run(feedbackTask);
}
return true;
}
use of com.intellij.util.Consumer in project intellij-plugins by JetBrains.
the class ShowUiRouterStatesNewDiagramAction method actionPerformed.
@Override
public void actionPerformed(AnActionEvent e) {
UsageTrigger.trigger(USAGE_KEY);
final Project project = e.getProject();
if (project == null)
return;
final AngularUiRouterDiagramProvider diagramProvider = (AngularUiRouterDiagramProvider) DiagramProvider.findByID(AngularUiRouterDiagramProvider.ANGULAR_UI_ROUTER);
if (diagramProvider == null)
return;
List<Pair<String, AngularUiRouterGraphBuilder>> graphBuilders = new ArrayList<>();
ProgressManager.getInstance().runProcessWithProgressSynchronously(() -> {
ApplicationManager.getApplication().runReadAction(() -> {
final AngularUiRouterDiagramBuilder builder = new AngularUiRouterDiagramBuilder(project);
builder.build();
final Map<VirtualFile, RootTemplate> rootTemplates = builder.getRootTemplates();
for (Map.Entry<VirtualFile, Map<String, UiRouterState>> entry : builder.getDefiningFiles2States().entrySet()) {
final AngularUiRouterGraphBuilder graphBuilder = new AngularUiRouterGraphBuilder(project, entry.getValue(), builder.getTemplatesMap(), null, entry.getKey());
graphBuilders.add(Pair.create(entry.getKey().getName(), graphBuilder));
}
for (Map.Entry<VirtualFile, Map<String, UiRouterState>> entry : builder.getRootTemplates2States().entrySet()) {
final AngularUiRouterGraphBuilder graphBuilder = new AngularUiRouterGraphBuilder(project, entry.getValue(), builder.getTemplatesMap(), rootTemplates.get(entry.getKey()), entry.getKey());
graphBuilders.add(Pair.create(entry.getKey().getName(), graphBuilder));
}
});
}, "Building " + diagramProvider.getPresentableName() + " diagram", false, project);
final AngularUiRouterProviderContext routerProviderContext = AngularUiRouterProviderContext.getInstance(project);
routerProviderContext.reset();
final Consumer<AngularUiRouterGraphBuilder> consumer = graphBuilder -> {
final AngularUiRouterGraphBuilder.GraphNodesBuilder nodesBuilder = graphBuilder.createDataModel(diagramProvider);
routerProviderContext.registerNodesBuilder(nodesBuilder);
final DiagramObject element = nodesBuilder.getRootNode().getIdentifyingElement();
final Runnable callback = show(element, diagramProvider, project, null, Collections.emptyList());
if (callback != null) {
callback.run();
}
};
if (graphBuilders.isEmpty()) {
Messages.showInfoMessage(project, "No router states found.", DESCRIPTION);
return;
}
if (graphBuilders.size() == 1)
consumer.consume(graphBuilders.get(0).getSecond());
else
filterGraphBuilders(project, graphBuilders, consumer);
}
Aggregations