本文整理汇总了Java中com.sun.tools.javac.main.JavaCompiler.errorCount方法的典型用法代码示例。如果您正苦于以下问题:Java JavaCompiler.errorCount方法的具体用法?Java JavaCompiler.errorCount怎么用?Java JavaCompiler.errorCount使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.sun.tools.javac.main.JavaCompiler
的用法示例。
在下文中一共展示了JavaCompiler.errorCount方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: test
import com.sun.tools.javac.main.JavaCompiler; //导入方法依赖的package包/类
static void test(JavacFileManager fm, JavaFileObject f, List<String> addExports, String... args) throws Throwable {
List<String> allArgs = new ArrayList<>();
allArgs.addAll(addExports);
allArgs.addAll(Arrays.asList(args));
Context context = new Context();
JavacTool tool = JavacTool.create();
JavacTaskImpl task = (JavacTaskImpl) tool.getTask(null, fm, null, allArgs, null, List.of(f), context);
task.call();
JavaCompiler c = JavaCompiler.instance(context);
if (c.errorCount() != 0)
throw new AssertionError("compilation failed");
long msec = c.elapsed_msec;
if (msec < 0 || msec > 5 * 60 * 1000) // allow test 5 mins to execute, should be more than enough!
throw new AssertionError("elapsed time is suspect: " + msec);
}
示例2: test
import com.sun.tools.javac.main.JavaCompiler; //导入方法依赖的package包/类
static void test(JavacFileManager fm, JavaFileObject f, String... args) throws Throwable {
Context context = new Context();
fm.setContext(context);
Main compilerMain = new Main("javac", new PrintWriter(System.err, true));
compilerMain.setOptions(Options.instance(context));
compilerMain.filenames = new LinkedHashSet<File>();
compilerMain.processArgs(args);
JavaCompiler c = JavaCompiler.instance(context);
c.compile(List.of(f));
if (c.errorCount() != 0)
throw new AssertionError("compilation failed");
long msec = c.elapsed_msec;
if (msec < 0 || msec > 5 * 60 * 1000) // allow test 5 mins to execute, should be more than enough!
throw new AssertionError("elapsed time is suspect: " + msec);
}
示例3: test
import com.sun.tools.javac.main.JavaCompiler; //导入方法依赖的package包/类
static void test(JavacFileManager fm, JavaFileObject f, String... args) throws Throwable {
Context context = new Context();
fm.setContext(context);
Main compilerMain = new Main("javac", new PrintWriter(System.err, true));
compilerMain.setOptions(Options.instance(context));
compilerMain.filenames = new ListBuffer<File>();
compilerMain.processArgs(args);
JavaCompiler c = JavaCompiler.instance(context);
c.compile(List.of(f));
if (c.errorCount() != 0)
throw new AssertionError("compilation failed");
long msec = c.elapsed_msec;
if (msec < 0 || msec > 5 * 60 * 1000) // allow test 5 mins to execute, should be more than enough!
throw new AssertionError("elapsed time is suspect: " + msec);
}
示例4: parseWithTargetCompiler
import com.sun.tools.javac.main.JavaCompiler; //导入方法依赖的package包/类
protected JCTree parseWithTargetCompiler(Source source) throws Exception {
Context context = new Context();
JavaCompiler compiler = new JavaCompiler(context);
compiler.genEndPos = true;
JCTree result = compiler.parse(new ContentBasedJavaFileObject(source.getName(), source.getRawInput()));
return compiler.errorCount() > 0 ? null : result;
}