Java Code Examples for com.intellij.util.ThrowableRunnable#run()

The following examples show how to use com.intellij.util.ThrowableRunnable#run() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestUtils.java    From intellij-plugin-v4 with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public static void tearDownIgnoringObjectNotDisposedException(ThrowableRunnable<Exception> delegate) throws Exception {
	try {
		delegate.run();
	} catch (RuntimeException e) {
		// We don't want to release the editor in the Tool Output tool window, so we ignore
		// ObjectNotDisposedExceptions related to this particular editor
		if ( e.getClass().getName().equals("com.intellij.openapi.util.TraceableDisposable$ObjectNotDisposedException")
				|| e instanceof CompoundRuntimeException ) {
			StringWriter stringWriter = new StringWriter();
			e.printStackTrace(new PrintWriter(stringWriter));
			String stack = stringWriter.toString();
			if ( stack.contains("ANTLRv4PluginController.createToolWindows")
					|| stack.contains("org.antlr.intellij.plugin.preview.InputPanel.createPreviewEditor") ) {
				return;
			}
		}

		throw e;
	}
}
 
Example 2
Source File: VcsSynchronousProgressWrapper.java    From consulo with Apache License 2.0 6 votes vote down vote up
public static boolean wrap(final ThrowableRunnable<VcsException> runnable, final Project project, final String title) {
  final VcsException[] exc = new VcsException[1];
  final Runnable process = new Runnable() {
    @Override
    public void run() {
      try {
        runnable.run();
      }
      catch (VcsException e) {
        exc[0] = e;
      }
    }
  };
  final boolean notCanceled;
  if (ApplicationManager.getApplication().isDispatchThread()) {
    notCanceled = ProgressManager.getInstance().runProcessWithProgressSynchronously(process, title, true, project);
  } else {
    process.run();
    notCanceled = true;
  }
  if (exc[0] != null) {
    AbstractVcsHelper.getInstance(project).showError(exc[0], title);
    return false;
  }
  return notCanceled;
}
 
Example 3
Source File: HTMLExportUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
public static void runExport(final Project project, @Nonnull ThrowableRunnable<IOException> runnable) {
  try {
    runnable.run();
  }
  catch (IOException e) {
    Runnable showError = new Runnable() {
      @Override
      public void run() {
        Messages.showMessageDialog(
          project,
          InspectionsBundle.message("inspection.export.error.writing.to", "export file"),
          InspectionsBundle.message("inspection.export.results.error.title"),
          Messages.getErrorIcon()
        );
      }
    };
    ApplicationManager.getApplication().invokeLater(showError, ModalityState.NON_MODAL);
    throw new ProcessCanceledException();
  }
}
 
Example 4
Source File: IndexInfrastructure.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void executeNestedInitializationTask(@Nonnull ThrowableRunnable<?> callable, CountDownLatch proceedLatch) {
  Application app = ApplicationManager.getApplication();
  try {
    // To correctly apply file removals in indices's shutdown hook we should process all initialization tasks
    // Todo: make processing removed files more robust because ignoring 'dispose in progress' delays application exit and
    // may cause memory leaks IDEA-183718, IDEA-169374,
    if (app.isDisposed() /*|| app.isDisposeInProgress()*/) return;
    callable.run();
  }
  catch (Throwable t) {
    onThrowable(t);
  }
  finally {
    proceedLatch.countDown();
  }
}
 
Example 5
Source File: MacOSDefaultMenuInitializer.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Inject
@ReviewAfterMigrationToJRE(9)
public MacOSDefaultMenuInitializer(AboutManager aboutManager, DataManager dataManager, WindowManager windowManager) {
  myAboutManager = aboutManager;
  myDataManager = dataManager;
  myWindowManager = windowManager;
  if (SystemInfo.isMac) {
    try {
      ThrowableRunnable<Throwable> task = SystemInfo.isJavaVersionAtLeast(9) ? new Java9Worker(this::showAbout) : new PreJava9Worker(this::showAbout);

      task.run();

      installAutoUpdateMenu();
    }
    catch (Throwable t) {
      LOGGER.warn(t);
    }
  }
}
 
Example 6
Source File: ComponentsCacheService.java    From litho with Apache License 2.0 5 votes vote down vote up
private void maybeUpdateInReadAction(
    PsiClass specClass, String componentQualifiedName, ShouldUpdateChecker checker) {
  final ThrowableRunnable<RuntimeException> job =
      () -> {
        if (checker.shouldStopUpdate()) return;

        final LayoutSpecModel layoutModel = ComponentGenerateUtils.createLayoutModel(specClass);
        update(componentQualifiedName, layoutModel);
      };
  if (ApplicationManager.getApplication().isReadAccessAllowed()) {
    job.run();
  } else {
    ReadAction.run(job);
  }
}
 
Example 7
Source File: CompilerUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static <T extends Throwable> void runInContext(CompileContext context, String title, ThrowableRunnable<T> action) throws T {
  if (title != null) {
    context.getProgressIndicator().pushState();
    context.getProgressIndicator().setText(title);
  }
  try {
    action.run();
  }
  finally {
    if (title != null) {
      context.getProgressIndicator().popState();
    }
  }
}
 
Example 8
Source File: DumbService.java    From consulo with Apache License 2.0 5 votes vote down vote up
/**
 * Invokes the given runnable with alternative resolve set to true.
 *
 * @see #setAlternativeResolveEnabled(boolean)
 */
public <E extends Throwable> void runWithAlternativeResolveEnabled(@Nonnull ThrowableRunnable<E> runnable) throws E {
  setAlternativeResolveEnabled(true);
  try {
    runnable.run();
  }
  finally {
    setAlternativeResolveEnabled(false);
  }
}
 
Example 9
Source File: VcsLogPersistentIndex.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static void catchAndWarn(@Nonnull ThrowableRunnable<IOException> runnable) {
  try {
    runnable.run();
  }
  catch (IOException e) {
    LOG.warn(e);
  }
}
 
Example 10
Source File: ClassLoaderUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static <E extends Throwable> void runWithClassLoader(final ClassLoader classLoader, final ThrowableRunnable<E> runnable) throws E {
  final ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
  try {
    Thread.currentThread().setContextClassLoader(classLoader);
    runnable.run();
  }
  finally {
    Thread.currentThread().setContextClassLoader(oldClassLoader);
  }
}
 
Example 11
Source File: PomModelImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static <T extends Throwable> void guardPsiModificationsIn(@Nonnull ThrowableRunnable<T> runnable) throws T {
  ApplicationManager.getApplication().assertWriteAccessAllowed();
  boolean old = allowPsiModification;
  try {
    allowPsiModification = false;
    runnable.run();
  }
  finally {
    allowPsiModification = old;
  }
}
 
Example 12
Source File: StartedActivated.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void callImpl(final MySection section, final boolean start) throws VcsException {
  final List<ThrowableRunnable<VcsException>> list = new ArrayList<ThrowableRunnable<VcsException>>(2);
  synchronized (myLock) {
    if (start) {
      section.start(list);
    } else {
      section.stop(list);
    }
  }
  for (ThrowableRunnable<VcsException> runnable : list) {
    runnable.run();
  }
}
 
Example 13
Source File: VfsAwareMapIndexStorage.java    From consulo with Apache License 2.0 5 votes vote down vote up
private <T extends Throwable> void withLock(ThrowableRunnable<T> r) throws T {
  myKeyHashToVirtualFileMapping.getPagedFileStorage().lock();
  try {
    r.run();
  }
  finally {
    myKeyHashToVirtualFileMapping.getPagedFileStorage().unlock();
  }
}
 
Example 14
Source File: BaseRefactoringProcessor.java    From consulo with Apache License 2.0 5 votes vote down vote up
@TestOnly
public static <T extends Throwable> void runWithDisabledPreview(ThrowableRunnable<T> runnable) throws T {
  PREVIEW_IN_TESTS = false;
  try {
    runnable.run();
  }
  finally {
    PREVIEW_IN_TESTS = true;
  }
}
 
Example 15
Source File: BaseRefactoringProcessor.java    From consulo with Apache License 2.0 5 votes vote down vote up
@TestOnly
public static <T extends Throwable> void withIgnoredConflicts(@Nonnull ThrowableRunnable<T> r) throws T {
  try {
    myTestIgnore = true;
    r.run();
  }
  finally {
    myTestIgnore = false;
  }
}