本文整理汇总了Java中com.sun.tools.javac.api.JavacTool.getStandardFileManager方法的典型用法代码示例。如果您正苦于以下问题:Java JavacTool.getStandardFileManager方法的具体用法?Java JavacTool.getStandardFileManager怎么用?Java JavacTool.getStandardFileManager使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.sun.tools.javac.api.JavacTool
的用法示例。
在下文中一共展示了JavacTool.getStandardFileManager方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: PubApiExtractor
import com.sun.tools.javac.api.JavacTool; //导入方法依赖的package包/类
/**
* Setup a compilation context, used for reading public apis of classes on the classpath
* as well as annotation processors.
*/
public PubApiExtractor(Options options) {
JavacTool compiler = com.sun.tools.javac.api.JavacTool.create();
fileManager = new SmartFileManager(compiler.getStandardFileManager(null, null, null));
context = new com.sun.tools.javac.util.Context();
String[] args = options.prepJavacArgs();
task = compiler.getTask(new PrintWriter(System.err),
fileManager,
null,
Arrays.asList(args),
null,
null,
context);
// Trigger a creation of the JavaCompiler, necessary to get a sourceCompleter for ClassFinder.
// The sourceCompleter is used for build situations where a classpath class references other classes
// that happens to be on the sourcepath.
JavaCompiler.instance(context);
// context.put(JavaFileManager.class, fileManager);
}
示例2: run
import com.sun.tools.javac.api.JavacTool; //导入方法依赖的package包/类
void run() throws Exception {
File testSrc = new File(System.getProperty("test.src"));
JavacTool tool = JavacTool.create();
try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) {
File f = new File(testSrc, T6993305.class.getSimpleName() + ".java");
Iterable<? extends JavaFileObject> fos = fm.getJavaFileObjects(f);
JavacTask task = tool.getTask(null, fm, null, null, null, fos);
Iterable<? extends CompilationUnitTree> cus = task.parse();
TestScanner s = new TestScanner();
s.scan(cus, task);
if (errors > 0)
throw new Exception(errors + " errors occurred");
}
}
示例3: main
import com.sun.tools.javac.api.JavacTool; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {
JavacTool tool = JavacTool.create();
try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) {
Iterable<? extends JavaFileObject> files =
fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrcDir, self + ".java")));
Iterable<String> options = Arrays.asList(
"--add-exports", "jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED",
"--processor-path", testClassDir,
"-processor", self,
"-s", ".",
"-d", ".");
JavacTask task = tool.getTask(out, fm, null, options, null, files);
VerifyingTaskListener vtl = new VerifyingTaskListener(new File(testSrcDir, self + ".out"));
task.setTaskListener(vtl);
if (!task.call())
throw new AssertionError("compilation failed");
if (vtl.iter.hasNext() || vtl.errors)
throw new AssertionError("comparison against golden file failed.");
}
}
示例4: main
import com.sun.tools.javac.api.JavacTool; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
PrintWriter out = new PrintWriter(System.out, true);
JavacTool tool = JavacTool.create();
try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) {
File testSrc = new File(System.getProperty("test.src"));
Iterable<? extends JavaFileObject> f =
fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, "T6345974.java")));
JavacTask task = tool.getTask(out, fm, null, null, null, f);
Iterable<? extends CompilationUnitTree> trees = task.parse();
out.flush();
Scanner s = new Scanner();
for (CompilationUnitTree t: trees)
s.scan(t, null);
}
}
示例5: run
import com.sun.tools.javac.api.JavacTool; //导入方法依赖的package包/类
/**
* method-run.
*/
void run() throws Exception {
File testSrc = new File(System.getProperty("test.src"));
File file = new File(testSrc, "TestDocComments.java");
JavacTool tool = JavacTool.create();
try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
Iterable<? extends JavaFileObject> fileObjects = fm.getJavaFileObjects(file);
JavacTask task = tool.getTask(pw, fm, null, null, null, fileObjects);
Iterable<? extends CompilationUnitTree> units = task.parse();
Trees trees = Trees.instance(task);
CommentScanner s = new CommentScanner();
int n = s.scan(units, trees);
if (n != 12)
error("Unexpected number of doc comments found: " + n);
if (errors > 0)
throw new Exception(errors + " errors occurred");
}
}
示例6: main
import com.sun.tools.javac.api.JavacTool; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
PrintWriter out = new PrintWriter(System.out, true);
JavacTool tool = JavacTool.create();
try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) {
File testSrc = new File(System.getProperty("test.src"));
Iterable<? extends JavaFileObject> f =
fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, "ArrayCreationTree.java")));
JavacTask task = tool.getTask(out, fm, null, null, null, f);
Iterable<? extends CompilationUnitTree> trees = task.parse();
out.flush();
Scanner s = new Scanner();
for (CompilationUnitTree t: trees)
s.scan(t, null);
}
}
示例7: main
import com.sun.tools.javac.api.JavacTool; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
PrintWriter out = new PrintWriter(System.out, true);
JavacTool tool = JavacTool.create();
try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) {
File testSrc = new File(System.getProperty("test.src"));
Iterable<? extends JavaFileObject> f =
fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, "AnnotatedArrayOrder.java")));
JavacTask task = tool.getTask(out, fm, null, null, null, f);
Iterable<? extends CompilationUnitTree> trees = task.parse();
out.flush();
Scanner s = new Scanner();
for (CompilationUnitTree t: trees)
s.scan(t, null);
}
}
示例8: main
import com.sun.tools.javac.api.JavacTool; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
PrintWriter out = new PrintWriter(System.out, true);
JavacTool tool = JavacTool.create();
try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) {
File testSrc = new File(System.getProperty("test.src"));
Iterable<? extends JavaFileObject> f =
fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, "ArrayPositionConsistency.java")));
JavacTask task = tool.getTask(out, fm, null, null, null, f);
Iterable<? extends CompilationUnitTree> trees = task.parse();
out.flush();
Scanner s = new Scanner();
for (CompilationUnitTree t: trees)
s.scan(t, null);
}
}
示例9: main
import com.sun.tools.javac.api.JavacTool; //导入方法依赖的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");
}
}
示例10: main
import com.sun.tools.javac.api.JavacTool; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {
JavacTool tool = JavacTool.create();
StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
Iterable<? extends JavaFileObject> files =
fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrcDir, self + ".java")));
Iterable<String> options = Arrays.asList("-processorpath", testClassDir,
"-processor", self,
"-s", ".",
"-d", ".");
JavacTask task = tool.getTask(out, fm, null, options, null, files);
VerifyingTaskListener vtl = new VerifyingTaskListener(new File(testSrcDir, self + ".out"));
task.setTaskListener(vtl);
if (!task.call())
throw new AssertionError("compilation failed");
if (vtl.iter.hasNext() || vtl.errors)
throw new AssertionError("comparison against golden file failed.");
}
示例11: main
import com.sun.tools.javac.api.JavacTool; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
PrintWriter out = new PrintWriter(System.out, true);
JavacTool tool = JavacTool.create();
StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
File testSrc = new File(System.getProperty("test.src"));
Iterable<? extends JavaFileObject> f =
fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, "ArrayPositionConsistency.java")));
JavacTask task = tool.getTask(out, fm, null, null, null, f);
Iterable<? extends CompilationUnitTree> trees = task.parse();
out.flush();
Scanner s = new Scanner();
for (CompilationUnitTree t: trees)
s.scan(t, null);
}
示例12: main
import com.sun.tools.javac.api.JavacTool; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
PrintWriter out = new PrintWriter(System.out, true);
JavacTool tool = JavacTool.create();
StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
File testSrc = new File(System.getProperty("test.src"));
Iterable<? extends JavaFileObject> f =
fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, "AnnotatedArrayOrder.java")));
JavacTask task = tool.getTask(out, fm, null, null, null, f);
Iterable<? extends CompilationUnitTree> trees = task.parse();
out.flush();
Scanner s = new Scanner();
for (CompilationUnitTree t: trees)
s.scan(t, null);
}
示例13: run
import com.sun.tools.javac.api.JavacTool; //导入方法依赖的package包/类
void run() throws Exception {
File testSrc = new File(System.getProperty("test.src"));
JavacTool tool = JavacTool.create();
StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
File f = new File(testSrc, T6993305.class.getSimpleName() + ".java");
Iterable<? extends JavaFileObject> fos = fm.getJavaFileObjects(f);
JavacTask task = tool.getTask(null, fm, null, null, null, fos);
Iterable<? extends CompilationUnitTree> cus = task.parse();
TestScanner s = new TestScanner();
s.scan(cus, task);
if (errors > 0)
throw new Exception(errors + " errors occurred");
}
示例14: testTaskAPI
import com.sun.tools.javac.api.JavacTool; //导入方法依赖的package包/类
void testTaskAPI(boolean expectWarnings, Iterable<? extends File> pcp) throws Exception {
System.err.println("test task API: " + pcp);
JavacTool tool = JavacTool.create();
StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
if (pcp != null)
fm.setLocation(StandardLocation.PLATFORM_CLASS_PATH, pcp);
Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(testFile);
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
JavacTask task = tool.getTask(pw, fm, null, null, null, files);
boolean ok = task.call();
String out = showOutput(sw.toString());
checkCompilationOK(ok);
checkOutput(out, expectWarnings);
}
示例15: run
import com.sun.tools.javac.api.JavacTool; //导入方法依赖的package包/类
void run() throws Exception {
List<File> files = new ArrayList<File>();
File testSrc = new File(System.getProperty("test.src"));
for (File f: testSrc.listFiles()) {
if (f.isFile() && f.getName().endsWith(".java"))
files.add(f);
}
JavacTool javac = JavacTool.create();
StandardJavaFileManager fm = javac.getStandardFileManager(null, null, null);
Iterable<? extends JavaFileObject> fos = fm.getJavaFileObjectsFromFiles(files);
JavacTask t = javac.getTask(null, fm, null, null, null, fos);
DocTrees trees = DocTrees.instance(t);
Iterable<? extends CompilationUnitTree> units = t.parse();
DeclScanner ds = new DeclScanner(trees);
for (CompilationUnitTree unit: units) {
ds.scan(unit, null);
}
if (errors > 0)
throw new Exception(errors + " errors occurred");
}