Context context = new Context();
Options options = Options.instance(context);
options.put("diags", "%b:%s/%o/%e:%_%t%m|%p%m");
Log log = Log.instance(context);
log.multipleErrors = true;
JavacFileManager.preRegister(context);
Scanner.Factory sfac = Scanner.Factory.instance(context);
Parser.Factory pfac = Parser.Factory.instance(context);
final String text =
"public class Foo {\n"
+ " public static void main(String[] args) {\n"
+ " if (args.length == 0)\n"
+ " System.out.println(\"no args\");\n"
+ " else\n"
+ " System.out.println(args.length + \" args\");\n"
+ " }\n"
+ "}\n";
JavaFileObject fo = new StringJavaFileObject("Foo", text);
log.useSource(fo);
Scanner s = sfac.newScanner(fo.getCharContent(true));
Parser parser = pfac.newParser(s, false, genEndPos);
JCTree.JCCompilationUnit tree = parser.compilationUnit();
log.setEndPosTable(fo, tree.endPositions);
TreeScanner ts = new LogTester(log, tree.endPositions);
ts.scan(tree);
check(log.nerrors, 4, "errors");