示例#1
0
 public void run() {
   Context ctx = new Context();
   Options options = Options.instance(ctx);
   outputKind.init(options);
   multiPolicy.init(options);
   xdiagsSource.init(options);
   xdiagsCompact.init(options);
   caretKind.init(options);
   sourceLineKind.init(options);
   String indentString = "";
   indentString = (summaryIndent == IndentKind.CUSTOM) ? "3" : "0";
   indentString += (detailsIndent == IndentKind.CUSTOM) ? "|3" : "|0";
   indentString += (sourceIndent == IndentKind.CUSTOM) ? "|3" : "|0";
   indentString += (subdiagsIndent == IndentKind.CUSTOM) ? "|3" : "|0";
   options.put("diagsIndentation", indentString);
   MyLog log = new MyLog(ctx);
   JavacMessages messages = JavacMessages.instance(ctx);
   messages.add("tester");
   JCDiagnostic.Factory diags = JCDiagnostic.Factory.instance(ctx);
   log.useSource(new MyFileObject("This is a source line"));
   JCDiagnostic d =
       diags.error(null, log.currentSource(), posKind.pos(), errorKind.key(), "Hello!");
   if (multiKind != MultilineKind.NONE) {
     JCDiagnostic sub = diags.fragment(errorKind.key(), "Hello!");
     if (multiKind.isNested()) sub = new JCDiagnostic.MultilineDiagnostic(sub, List.of(sub));
     List<JCDiagnostic> subdiags = multiKind.isDouble() ? List.of(sub, sub) : List.of(sub);
     d = new JCDiagnostic.MultilineDiagnostic(d, subdiags);
   }
   String diag = log.getDiagnosticFormatter().format(d, messages.getCurrentLocale());
   checkOutput(diag);
 }
示例#2
0
    String getOutput(
        OutputKind outKind,
        ErrorKind errKind,
        MultilinePolicy policy,
        IndentKind summaryIndent,
        IndentKind detailsIndent,
        IndentKind multiIndent) {
      String constIndent =
          (errKind == ErrorKind.DOUBLE)
              ? summaryIndent.string + detailsIndent.string
              : summaryIndent.string;
      constIndent += multiIndent.string;

      String errMsg1 = errKind.getOutput(outKind, summaryIndent, detailsIndent, constIndent);
      String errMsg2 =
          errKind.getOutput(outKind, summaryIndent, detailsIndent, constIndent + constIndent);

      errMsg1 = errMsg1.replaceAll("compiler.err", "compiler.misc");
      errMsg1 = errMsg1.replaceAll("error message", "subdiagnostic");
      errMsg2 = errMsg2.replaceAll("compiler.err", "compiler.misc");
      errMsg2 = errMsg2.replaceAll("error message", "subdiagnostic");

      String template =
          outKind == OutputKind.RAW
              ? rawTemplates[policy.index][index]
              : basicTemplates[policy.index][index];

      template = template.replaceAll("E", errMsg1);
      return template.replaceAll("Q", errMsg2);
    }
示例#3
0
 void printInfo(String msg, String errorLine) {
   String sep = "*********************************************************";
   String desc =
       "raw="
           + outputKind
           + " pos="
           + posKind
           + " key="
           + errorKind.key()
           + " multiline="
           + multiKind
           + " multiPolicy="
           + multiPolicy.value
           + " diags= "
           + java.util.Arrays.asList(xdiagsSource.flag, xdiagsCompact.flag)
           + " caret="
           + caretKind
           + " sourcePosition="
           + sourceLineKind
           + " summaryIndent="
           + summaryIndent
           + " detailsIndent="
           + detailsIndent
           + " sourceIndent="
           + sourceIndent
           + " subdiagsIndent="
           + subdiagsIndent;
   System.err.println(sep);
   System.err.println(desc);
   System.err.println(sep);
   System.err.println(msg);
   System.err.println("Diagnostic formatting problem - expected diagnostic...\n" + errorLine);
 }
示例#4
0
 public static void main(String[] args) throws Exception {
   for (OutputKind outputKind : OutputKind.values()) {
     for (ErrorKind errKind : ErrorKind.values()) {
       for (MultilineKind multiKind : MultilineKind.values()) {
         for (MultilinePolicy multiPolicy : MultilinePolicy.values()) {
           for (PositionKind posKind : PositionKind.values()) {
             for (XDiagsSource xdiagsSource : XDiagsSource.values()) {
               for (XDiagsCompact xdiagsCompact : XDiagsCompact.values()) {
                 for (CaretKind caretKind : CaretKind.values()) {
                   for (SourceLineKind sourceLineKind : SourceLineKind.values()) {
                     for (IndentKind summaryIndent : IndentKind.values()) {
                       for (IndentKind detailsIndent : IndentKind.values()) {
                         for (IndentKind sourceIndent : IndentKind.values()) {
                           for (IndentKind subdiagsIndent : IndentKind.values()) {
                             new T6769027(
                                     outputKind,
                                     errKind,
                                     multiKind,
                                     multiPolicy,
                                     posKind,
                                     xdiagsSource,
                                     xdiagsCompact,
                                     caretKind,
                                     sourceLineKind,
                                     summaryIndent,
                                     detailsIndent,
                                     sourceIndent,
                                     subdiagsIndent)
                                 .run();
                           }
                         }
                       }
                     }
                   }
                 }
               }
             }
           }
         }
       }
     }
   }
 }
示例#5
0
  void checkOutput(String msg) {
    boolean shouldPrintSource =
        posKind == PositionKind.POS
            && xdiagsSource != XDiagsSource.NO_SOURCE
            && (xdiagsSource == XDiagsSource.SOURCE || outputKind == OutputKind.BASIC);
    String errorLine =
        posKind.getOutput(outputKind)
            + errorKind.getOutput(outputKind, summaryIndent, detailsIndent);
    if (xdiagsCompact != XDiagsCompact.COMPACT)
      errorLine +=
          multiKind.getOutput(
              outputKind, errorKind, multiPolicy, summaryIndent, detailsIndent, subdiagsIndent);
    String[] lines = errorLine.split("\n");
    if (xdiagsCompact == XDiagsCompact.COMPACT) {
      errorLine = lines[0];
      lines = new String[] {errorLine};
    }
    if (shouldPrintSource) {
      if (sourceLineKind.isAfterSummary()) {
        String sep = "\n";
        if (lines.length == 1) {
          errorLine += "\n";
          sep = "";
        }
        errorLine =
            errorLine.replaceFirst(
                "\n",
                Matcher.quoteReplacement(
                    xdiagsSource.getOutput(caretKind, sourceIndent, outputKind) + sep));
      } else errorLine += xdiagsSource.getOutput(caretKind, sourceIndent, outputKind);
    }

    if (!msg.equals(errorLine)) {
      printInfo(msg, errorLine);
      throw new AssertionError("errors were found");
    }
  }