本文整理汇总了Java中com.sun.source.util.JavacTask.instance方法的典型用法代码示例。如果您正苦于以下问题:Java JavacTask.instance方法的具体用法?Java JavacTask.instance怎么用?Java JavacTask.instance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.sun.source.util.JavacTask
的用法示例。
在下文中一共展示了JavacTask.instance方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: init
import com.sun.source.util.JavacTask; //导入方法依赖的package包/类
/*****************************************
* Add task to the javac compilation process
* @param pe the processing environment
****************************************/
@Override
public synchronized void init(ProcessingEnvironment pe) {
JavacTask task = JavacTask.instance(pe);
if (!(task instanceof BasicJavacTask)) {
pe.getMessager()
.printMessage(Diagnostic.Kind.WARNING,
"Unfortunately you are using an incompatible " +
"version of the javac. Please report this at " +
"https://github.com/prestongarno/trywithres-compat/issues. Thank you.");
return;
}
super.init(pe);
task.addTaskListener(new Loader.TaskListenerImpl(task));
String v = Options.instance(((BasicJavacTask) task).getContext()).get("-g:source");
INJECT_STDOUT_STATEMENT = v != null;
}
示例2: add
import com.sun.source.util.JavacTask; //导入方法依赖的package包/类
public static void add(ProcessingEnvironment env, Runnable r) {
// ensure this class in this class loader can access javac internals
try {
JavacTask task = JavacTask.instance(env);
TaskListener l = ((BasicJavacTask) task).getTaskListeners().iterator().next();
// The TaskListener is an instanceof TestClose, but when using the
// default class loaders. the taskListener uses a different
// instance of Class<TestClose> than the anno processor.
// If you try to evaluate
// TestClose tc = (TestClose) (l).
// you get the following somewhat confusing error:
// java.lang.ClassCastException: TestClose cannot be cast to TestClose
// The workaround is to access the fields of TestClose with reflection.
Field f = l.getClass().getField("runnables");
@SuppressWarnings("unchecked")
List<Runnable> runnables = (List<Runnable>) f.get(l);
runnables.add(r);
} catch (Throwable t) {
t.printStackTrace();
}
}
示例3: process
import com.sun.source.util.JavacTask; //导入方法依赖的package包/类
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
// System.err.println("TestProcessor.process " + roundEnv);
JavacTask task = JavacTask.instance(processingEnv);
if (++round == 1) {
switch (ak) {
case ADD_IN_PROCESSOR:
task.addTaskListener(listener);
break;
case ADD_IN_LISTENER:
addInListener(task, TaskEvent.Kind.ANALYZE, listener);
break;
}
} else if (roundEnv.processingOver()) {
switch (rk) {
case REMOVE_IN_PROCESSOR:
task.removeTaskListener(listener);
break;
case REMOVE_IN_LISTENER:
removeInListener(task, TaskEvent.Kind.GENERATE, listener);
break;
}
}
return true;
}