本文整理汇总了Java中com.sun.tools.javac.api.JavacTaskImpl.getElements方法的典型用法代码示例。如果您正苦于以下问题:Java JavacTaskImpl.getElements方法的具体用法?Java JavacTaskImpl.getElements怎么用?Java JavacTaskImpl.getElements使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.sun.tools.javac.api.JavacTaskImpl
的用法示例。
在下文中一共展示了JavacTaskImpl.getElements方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import com.sun.tools.javac.api.JavacTaskImpl; //导入方法依赖的package包/类
public static void main(String... args) throws IOException {
JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) {
String srcdir = System.getProperty("test.src");
File file = new File(srcdir, args[0]);
List<String> options = Arrays.asList(
"--add-exports", "jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED"
);
JavacTaskImpl task = (JavacTaskImpl)tool.getTask(null, fm, null, options, null, fm.getJavaFileObjectsFromFiles(Arrays.asList(file)));
Elements elements = task.getElements();
for (Element clazz : task.enter(task.parse())) {
String doc = elements.getDocComment(clazz);
if (doc == null)
throw new AssertionError(clazz.getSimpleName() + ": no doc comment");
System.out.format("%s: %s%n", clazz.getSimpleName(), doc);
}
}
}
示例2: main
import com.sun.tools.javac.api.JavacTaskImpl; //导入方法依赖的package包/类
public static void main(String... args) throws IOException {
if (args.length < 1) {
help();
return ;
}
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
List<String> options = Arrays.asList("-source", "9",
"-target", "9",
"-proc:only",
"--system", "none",
"--module-source-path", args[0],
"--add-modules", Arrays.stream(args)
.skip(1)
.collect(Collectors.joining(",")));
List<String> jlObjectList = Arrays.asList("java.lang.Object");
JavacTaskImpl task = (JavacTaskImpl) compiler.getTask(null, null, null, options, jlObjectList, null);
task.enter();
Elements elements = task.getElements();
List<String> todo = new LinkedList<>();
Arrays.stream(args).skip(1).forEach(todo::add);
Set<String> allModules = new HashSet<>();
while (!todo.isEmpty()) {
String current = todo.remove(0);
if (!allModules.add(current))
continue;
ModuleSymbol mod = (ModuleSymbol) elements.getModuleElement(current);
if (mod == null) {
throw new IllegalStateException("Missing: " + current);
}
//use the internal structure to avoid unnecesarily completing the symbol using the UsesProvidesVisitor:
for (RequiresDirective rd : mod.requires) {
if (rd.isTransitive()) {
todo.add(rd.getDependency().getQualifiedName().toString());
}
}
}
allModules.add("java.base");
allModules.add("jdk.unsupported");
allModules.stream()
.sorted()
.forEach(System.out::println);
}