本文整理匯總了Java中com.sun.source.util.JavacTask.generate方法的典型用法代碼示例。如果您正苦於以下問題:Java JavacTask.generate方法的具體用法?Java JavacTask.generate怎麽用?Java JavacTask.generate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.sun.source.util.JavacTask
的用法示例。
在下文中一共展示了JavacTask.generate方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: compile
import com.sun.source.util.JavacTask; //導入方法依賴的package包/類
private File compile(List<File> classpaths, List<JavaFileObject> files, boolean generate) throws IOException {
JavaCompiler systemJavaCompiler = ToolProvider.getSystemJavaCompiler();
try (StandardJavaFileManager fm = systemJavaCompiler.getStandardFileManager(null, null, null)) {
if (classpaths.size() > 0)
fm.setLocation(StandardLocation.CLASS_PATH, classpaths);
JavacTask ct = (JavacTask) systemJavaCompiler.getTask(null, fm, diags, compileOptions, null, files);
if (generate) {
File destDir = new File(root, Integer.toString(counter.incrementAndGet()));
// @@@ Assert that this directory didn't exist, or start counter at max+1
destDir.mkdirs();
fm.setLocation(StandardLocation.CLASS_OUTPUT, Arrays.asList(destDir));
ct.generate();
return destDir;
}
else {
ct.analyze();
return nullDir;
}
}
}
示例2: main
import com.sun.source.util.JavacTask; //導入方法依賴的package包/類
public static void main(String... args) throws IOException {
String testSrc = System.getProperty("test.src", ".");
String testClasses = System.getProperty("test.classes", ".");
JavacTool tool = JavacTool.create();
MyDiagListener dl = new MyDiagListener();
try (StandardJavaFileManager fm = tool.getStandardFileManager(dl, null, null)) {
fm.setLocation(StandardLocation.CLASS_OUTPUT, Arrays.asList(new File(testClasses)));
Iterable<? extends JavaFileObject> files =
fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, T6410706.class.getName()+".java")));
JavacTask task = tool.getTask(null, fm, dl, null, null, files);
task.parse();
task.analyze();
task.generate();
// expect 2 notes:
// Note: T6410706.java uses or overrides a deprecated API.
// Note: Recompile with -Xlint:deprecation for details.
if (dl.notes != 2)
throw new AssertionError(dl.notes + " notes given");
}
}
示例3: runTest
import com.sun.source.util.JavacTask; //導入方法依賴的package包/類
private void runTest(String code, String expectedDesugar) throws Exception {
List<JavaFileObject> files = List.nil();
for (String file : code.split("---")) {
files = files.prepend(new ToolBox.JavaSource(file));
}
Path classes = Paths.get("classes");
if (Files.exists(classes)) {
tb.cleanDirectory(classes);
} else {
Files.createDirectories(classes);
}
JavacTool compiler = (JavacTool) ToolProvider.getSystemJavaCompiler();
StringWriter out = new StringWriter();
Context context = new Context();
TestLower.preRegister(context);
Iterable<String> options = Arrays.asList("-d", classes.toString());
JavacTask task = (JavacTask) compiler.getTask(out, null, null, options, null, files, context);
task.generate();
out.flush();
String actual = out.toString().replace(System.getProperty("line.separator"), "\n");
if (!expectedDesugar.equals(actual)) {
throw new IllegalStateException("Actual does not match expected: " + actual);
}
}
示例4: compileAndCheck
import com.sun.source.util.JavacTask; //導入方法依賴的package包/類
void compileAndCheck(VarargsMethod m1, VarargsMethod m2, TypeKind actual, ArgumentsArity argsArity) throws Exception {
final JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
JavaSource source = new JavaSource(m1, m2, actual, argsArity);
ErrorChecker ec = new ErrorChecker();
JavacTask ct = (JavacTask)tool.getTask(null, fm, ec,
null, null, Arrays.asList(source));
ct.generate();
check(source, ec, m1, m2, actual, argsArity);
}
示例5: run
import com.sun.source.util.JavacTask; //導入方法依賴的package包/類
void run(JavacTask t) throws IOException {
t.generate();
}