本文整理汇总了Java中com.sun.tools.javac.file.JavacFileManager.setContext方法的典型用法代码示例。如果您正苦于以下问题:Java JavacFileManager.setContext方法的具体用法?Java JavacFileManager.setContext怎么用?Java JavacFileManager.setContext使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.sun.tools.javac.file.JavacFileManager
的用法示例。
在下文中一共展示了JavacFileManager.setContext方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: test
import com.sun.tools.javac.file.JavacFileManager; //导入方法依赖的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);
}
示例2: testNoAnnotationProcessing
import com.sun.tools.javac.file.JavacFileManager; //导入方法依赖的package包/类
static void testNoAnnotationProcessing(JavacFileManager fm, JavaFileObject f) 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(new String[] { "-d", "." });
JavaCompiler compiler = JavaCompiler.instance(context);
compiler.compile(List.of(f));
try {
compiler.compile(List.of(f));
throw new Error("Error: AssertionError not thrown after second call of compile");
} catch (AssertionError e) {
System.err.println("Exception from compiler (expected): " + e);
}
}
示例3: testAnnotationProcessing
import com.sun.tools.javac.file.JavacFileManager; //导入方法依赖的package包/类
static void testAnnotationProcessing(JavacFileManager fm, JavaFileObject f) 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(new String[] {
"-XprintRounds",
"-processorpath", testClasses,
"-processor", self,
"-d", "."});
JavaCompiler compiler = JavaCompiler.instance(context);
compiler.initProcessAnnotations(null);
JavaCompiler compiler2 = compiler.processAnnotations(compiler.enterTrees(compiler.parseFiles(List.of(f))));
try {
compiler2.compile(List.of(f));
throw new Error("Error: AssertionError not thrown after second call of compile");
} catch (AssertionError e) {
System.err.println("Exception from compiler (expected): " + e);
}
}