コード例 #1
0
 public static <T> void assertUnorderedCollection(
     Collection<? extends T> collection, Consumer<T>... checkers) {
   Assert.assertNotNull(collection);
   if (collection.size() != checkers.length) {
     Assert.fail(toString(collection));
   }
   Set<Consumer<T>> checkerSet = new HashSet<Consumer<T>>(Arrays.asList(checkers));
   int i = 0;
   Throwable lastError = null;
   for (final T actual : collection) {
     boolean flag = true;
     for (final Consumer<T> condition : checkerSet) {
       Throwable error = accepts(condition, actual);
       if (error == null) {
         checkerSet.remove(condition);
         flag = false;
         break;
       } else {
         lastError = error;
       }
     }
     if (flag) {
       lastError.printStackTrace();
       Assert.fail("Incorrect element(" + i + "): " + actual);
     }
     i++;
   }
 }
コード例 #2
0
 protected void assertNoThrowable(final Runnable closure) {
   String throwableName = null;
   try {
     closure.run();
   } catch (Throwable thr) {
     throwableName = thr.getClass().getName();
   }
   assertNull(throwableName);
 }
コード例 #3
0
 private void registerParsingException(final CompilerParsingThread outputParsingThread) {
   Throwable error = outputParsingThread == null ? null : outputParsingThread.getError();
   if (error != null) {
     String message = error.getMessage();
     if (error instanceof CacheCorruptedException) {
       myCompileContext.requestRebuildNextTime(message);
     } else {
       myCompileContext.addMessage(CompilerMessageCategory.ERROR, message, null, -1, -1);
     }
   }
 }
コード例 #4
0
  @NonNls
  private static String message(Throwable e) {
    String message = e.getMessage();
    if (message != null) return message;
    message = e.getLocalizedMessage();
    if (message != null) return message;
    message = e.toString();
    Throwable cause = e.getCause();
    if (cause != null) {
      String causeMessage = message(cause);
      return message + " (cause: " + causeMessage + ")";
    }

    return message;
  }
コード例 #5
0
 @Override
 protected void handleInitComponentError(
     final Throwable ex, final boolean fatal, final String componentClassName) {
   if (PluginManager.isPluginClass(componentClassName)) {
     LOG.error(ex);
     PluginId pluginId = PluginManager.getPluginByClassName(componentClassName);
     @NonNls
     final String errorMessage =
         "Plugin "
             + pluginId.getIdString()
             + " failed to initialize and will be disabled:\n"
             + ex.getMessage()
             + "\nPlease restart "
             + ApplicationNamesInfo.getInstance().getFullProductName()
             + ".";
     PluginManager.disablePlugin(pluginId.getIdString());
     if (!myHeadlessMode) {
       JOptionPane.showMessageDialog(null, errorMessage);
     } else {
       //noinspection UseOfSystemOutOrSystemErr
       System.out.println(errorMessage);
       System.exit(1);
     }
     return; // do not call super
   }
   if (fatal) {
     LOG.error(ex);
     @NonNls
     final String errorMessage =
         "Fatal error initializing class "
             + componentClassName
             + ":\n"
             + ex.toString()
             + "\nComplete error stacktrace was written to idea.log";
     if (!myHeadlessMode) {
       JOptionPane.showMessageDialog(null, errorMessage);
     } else {
       //noinspection UseOfSystemOutOrSystemErr
       System.out.println(errorMessage);
     }
   }
   super.handleInitComponentError(ex, fatal, componentClassName);
 }
コード例 #6
0
  private static void assertExceptionOccurred(
      boolean shouldOccur, AbstractExceptionCase exceptionCase, String expectedErrorMsg)
      throws Throwable {
    boolean wasThrown = false;
    try {
      exceptionCase.tryClosure();
    } catch (Throwable e) {
      if (shouldOccur) {
        wasThrown = true;
        final String errorMessage = exceptionCase.getAssertionErrorMessage();
        assertEquals(errorMessage, exceptionCase.getExpectedExceptionClass(), e.getClass());
        if (expectedErrorMsg != null) {
          assertEquals("Compare error messages", expectedErrorMsg, e.getMessage());
        }
      } else if (exceptionCase.getExpectedExceptionClass().equals(e.getClass())) {
        wasThrown = true;

        System.out.println("");
        e.printStackTrace(System.out);

        fail("Exception isn't expected here. Exception message: " + e.getMessage());
      } else {
        throw e;
      }
    } finally {
      if (shouldOccur && !wasThrown) {
        fail(exceptionCase.getAssertionErrorMessage());
      }
    }
  }
コード例 #7
0
 public void _saveSettings() { // public for testing purposes
   if (mySaveSettingsIsInProgress.compareAndSet(false, true)) {
     try {
       doSave();
     } catch (final Throwable ex) {
       if (isUnitTestMode()) {
         System.out.println("Saving application settings failed");
         ex.printStackTrace();
       } else {
         LOG.info("Saving application settings failed", ex);
         invokeLater(
             new Runnable() {
               public void run() {
                 if (ex instanceof PluginException) {
                   final PluginException pluginException = (PluginException) ex;
                   PluginManager.disablePlugin(pluginException.getPluginId().getIdString());
                   Messages.showMessageDialog(
                       "The plugin "
                           + pluginException.getPluginId()
                           + " failed to save settings and has been disabled. Please restart "
                           + ApplicationNamesInfo.getInstance().getFullProductName(),
                       CommonBundle.getErrorTitle(),
                       Messages.getErrorIcon());
                 } else {
                   Messages.showMessageDialog(
                       ApplicationBundle.message(
                           "application.save.settings.error", ex.getLocalizedMessage()),
                       CommonBundle.getErrorTitle(),
                       Messages.getErrorIcon());
                 }
               }
             });
       }
     } finally {
       mySaveSettingsIsInProgress.set(false);
     }
   }
 }
コード例 #8
0
  @TestOnly
  public List<HighlightInfo> runPasses(
      @NotNull PsiFile file,
      @NotNull Document document,
      @NotNull TextEditor textEditor,
      @NotNull int[] toIgnore,
      boolean canChangeDocument,
      @Nullable Runnable callbackWhileWaiting) {
    assert myInitialized;
    assert !myDisposed;
    Application application = ApplicationManager.getApplication();
    application.assertIsDispatchThread();
    assert !application.isWriteAccessAllowed();

    // pump first so that queued event do not interfere
    UIUtil.dispatchAllInvocationEvents();
    UIUtil.dispatchAllInvocationEvents();

    Project project = file.getProject();
    setUpdateByTimerEnabled(false);
    FileStatusMap fileStatusMap = getFileStatusMap();
    for (int ignoreId : toIgnore) {
      fileStatusMap.markFileUpToDate(document, ignoreId);
    }
    fileStatusMap.allowDirt(canChangeDocument);

    TextEditorBackgroundHighlighter highlighter =
        (TextEditorBackgroundHighlighter) textEditor.getBackgroundHighlighter();
    final List<TextEditorHighlightingPass> passes = highlighter.getPasses(toIgnore);
    HighlightingPass[] array = passes.toArray(new HighlightingPass[passes.size()]);

    final DaemonProgressIndicator progress = createUpdateProgress();
    progress.setDebug(LOG.isDebugEnabled());
    myPassExecutorService.submitPasses(
        Collections.singletonMap((FileEditor) textEditor, array), progress, Job.DEFAULT_PRIORITY);
    try {
      while (progress.isRunning()) {
        try {
          if (progress.isCanceled() && progress.isRunning()) {
            // write action sneaked in the AWT. restart
            waitForTermination();
            Throwable savedException = PassExecutorService.getSavedException(progress);
            if (savedException != null) throw savedException;
            return runPasses(
                file, document, textEditor, toIgnore, canChangeDocument, callbackWhileWaiting);
          }
          if (callbackWhileWaiting != null) {
            callbackWhileWaiting.run();
          }
          progress.waitFor(100);
          UIUtil.dispatchAllInvocationEvents();
          Throwable savedException = PassExecutorService.getSavedException(progress);
          if (savedException != null) throw savedException;
        } catch (RuntimeException e) {
          throw e;
        } catch (Error e) {
          e.printStackTrace();
          throw e;
        } catch (Throwable e) {
          e.printStackTrace();
          throw new RuntimeException(e);
        }
      }
      UIUtil.dispatchAllInvocationEvents();
      UIUtil.dispatchAllInvocationEvents();

      return getHighlights(document, null, project);
    } finally {
      fileStatusMap.allowDirt(true);
      waitForTermination();
    }
  }