Пример #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
 private void prepareCompiler() throws IOException {
   if (used.getAndSet(true)) {
     if (compiler == null) throw new IllegalStateException();
   } else {
     initContext();
     compilerMain.setOptions(Options.instance(context));
     compilerMain.filenames = new LinkedHashSet<File>();
     Collection<File> filenames = compilerMain.processArgs(CommandLine.parse(args), classNames);
     if (!filenames.isEmpty())
       throw new IllegalArgumentException("Malformed arguments " + toString(filenames, " "));
     compiler = JavaCompiler.instance(context);
     compiler.keepComments = true;
     compiler.genEndPos = true;
     // NOTE: this value will be updated after annotation processing
     compiler.initProcessAnnotations(processors);
     notYetEntered = new HashMap<JavaFileObject, JCCompilationUnit>();
     for (JavaFileObject file : fileObjects) notYetEntered.put(file, null);
     genList = new ListBuffer<Env<AttrContext>>();
     // endContext will be called when all classes have been generated
     // TODO: should handle the case after each phase if errors have occurred
     args = null;
     classNames = null;
   }
 }