Example #1
0
  /** Construct a log with given I/O redirections. */
  protected Log(
      Context context, PrintWriter errWriter, PrintWriter warnWriter, PrintWriter noticeWriter) {
    super(JCDiagnostic.Factory.instance(context));
    context.put(logKey, this);
    this.errWriter = errWriter;
    this.warnWriter = warnWriter;
    this.noticeWriter = noticeWriter;

    @SuppressWarnings("unchecked") // FIXME
    DiagnosticListener<? super JavaFileObject> dl = context.get(DiagnosticListener.class);
    this.diagListener = dl;

    diagnosticHandler = new DefaultDiagnosticHandler();

    messages = JavacMessages.instance(context);
    messages.add(Main.javacBundleName);

    final Options options = Options.instance(context);
    initOptions(options);
    options.addListener(
        new Runnable() {
          public void run() {
            initOptions(options);
          }
        });
  }
Example #2
0
  /** Write out a diagnostic. */
  protected void writeDiagnostic(JCDiagnostic diag) {
    if (diagListener != null) {
      diagListener.report(diag);
      return;
    }

    PrintWriter writer = getWriterForDiagnosticType(diag.getType());

    printRawLines(writer, diagFormatter.format(diag, messages.getCurrentLocale()));

    if (promptOnError) {
      switch (diag.getType()) {
        case ERROR:
        case WARNING:
          prompt();
      }
    }

    if (dumpOnError) new RuntimeException().printStackTrace(writer);

    writer.flush();
  }
Example #3
0
 /**
  * Find a localized string in the resource bundle.
  *
  * @param key The key for the localized string.
  * @param args Fields to substitute into the string.
  */
 public String localize(PrefixKind pk, String key, Object... args) {
   if (useRawMessages) return pk.key(key);
   else return messages.getLocalizedString(pk.key(key), args);
 }
Example #4
0
 /**
  * Find a localized string in the resource bundle. Because this method is static, it ignores the
  * locale. Use localize(key, args) when possible.
  *
  * @param key The key for the localized string.
  * @param args Fields to substitute into the string.
  */
 public static String getLocalizedString(String key, Object... args) {
   return JavacMessages.getDefaultLocalizedString(PrefixKind.COMPILER_MISC.key(key), args);
 }