本文整理汇总了Java中com.sun.source.util.TaskListener类的典型用法代码示例。如果您正苦于以下问题:Java TaskListener类的具体用法?Java TaskListener怎么用?Java TaskListener使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TaskListener类属于com.sun.source.util包,在下文中一共展示了TaskListener类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: add
import com.sun.source.util.TaskListener; //导入依赖的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();
}
}
示例2: getTask
import com.sun.source.util.TaskListener; //导入依赖的package包/类
/**
* Fork a new compilation task; if possible the compilation context from previous executions is
* retained (see comments in ReusableContext as to when it's safe to do so); otherwise a brand
* new context is created.
*/
public JavacTask getTask() {
if (task == null) {
ReusableContext context = env.context();
String opts = options == null ? "" :
StreamSupport.stream(options.spliterator(), false).collect(Collectors.joining());
context.clear();
if (!context.polluted && (context.opts == null || context.opts.equals(opts))) {
//we can reuse former context
env.info().ctxReusedCount++;
} else {
env.info().ctxDroppedCount++;
//it's not safe to reuse context - create a new one
context = env.setContext(new ReusableContext());
}
context.opts = opts;
JavacTask javacTask = ((JavacTool)env.javaCompiler()).getTask(out, env.fileManager(),
diagsCollector, options, null, sources, context);
javacTask.setTaskListener(context);
for (TaskListener l : listeners) {
javacTask.addTaskListener(l);
}
task = javacTask;
}
return task;
}
示例3: add
import com.sun.source.util.TaskListener; //导入依赖的package包/类
public static void add(ProcessingEnvironment env, Runnable r) {
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();
}
}
示例4: runLastRound
import com.sun.source.util.TaskListener; //导入依赖的package包/类
private void runLastRound(PrintWriter xout,
int roundNumber,
boolean errorStatus,
TaskListener taskListener) throws IOException {
roundNumber++;
List<ClassSymbol> noTopLevelClasses = List.nil();
Set<TypeElement> noAnnotations = Collections.emptySet();
printRoundInfo(xout, roundNumber, noTopLevelClasses, noAnnotations, true);
Set<Element> emptyRootElements = Collections.emptySet(); // immutable
RoundEnvironment renv = new JavacRoundEnvironment(true,
errorStatus,
emptyRootElements,
JavacProcessingEnvironment.this);
if (taskListener != null)
taskListener.started(new TaskEvent(TaskEvent.Kind.ANNOTATION_PROCESSING_ROUND));
try {
discoveredProcs.iterator().runContributingProcs(renv);
} finally {
if (taskListener != null)
taskListener.finished(new TaskEvent(TaskEvent.Kind.ANNOTATION_PROCESSING_ROUND));
}
}
示例5: run
import com.sun.source.util.TaskListener; //导入依赖的package包/类
/** Run a processing round. */
void run(boolean lastRound, boolean errorStatus) {
printRoundInfo(lastRound);
TaskListener taskListener = context.get(TaskListener.class);
if (taskListener != null)
taskListener.started(new TaskEvent(TaskEvent.Kind.ANNOTATION_PROCESSING_ROUND));
try {
if (lastRound) {
filer.setLastRound(true);
Set<Element> emptyRootElements = Collections.emptySet(); // immutable
RoundEnvironment renv = new JavacRoundEnvironment(true,
errorStatus,
emptyRootElements,
JavacProcessingEnvironment.this);
discoveredProcs.iterator().runContributingProcs(renv);
} else {
discoverAndRunProcs(context, annotationsPresent, topLevelClasses, packageInfoFiles);
}
} finally {
if (taskListener != null)
taskListener.finished(new TaskEvent(TaskEvent.Kind.ANNOTATION_PROCESSING_ROUND));
}
nMessagerErrors = messager.errorCount();
}
示例6: add
import com.sun.source.util.TaskListener; //导入依赖的package包/类
public void add(TaskListener listener) {
for (TaskListener l: listeners) {
if (ccw.unwrap(l) == listener)
throw new IllegalStateException();
}
listeners = Arrays.copyOf(listeners, listeners.length + 1);
listeners[listeners.length - 1] = ccw.wrap(listener);
}
示例7: remove
import com.sun.source.util.TaskListener; //导入依赖的package包/类
public void remove(TaskListener listener) {
for (int i = 0; i < listeners.length; i++) {
if (ccw.unwrap(listeners[i]) == listener) {
TaskListener[] newListeners = new TaskListener[listeners.length - 1];
System.arraycopy(listeners, 0, newListeners, 0, i);
System.arraycopy(listeners, i + 1, newListeners, i, newListeners.length - i);
listeners = newListeners;
break;
}
}
}
示例8: started
import com.sun.source.util.TaskListener; //导入依赖的package包/类
@Override
public void started(TaskEvent e) {
// guard against listeners being updated by a listener
TaskListener[] ll = this.listeners;
for (TaskListener l: ll)
l.started(e);
}
示例9: finished
import com.sun.source.util.TaskListener; //导入依赖的package包/类
@Override
public void finished(TaskEvent e) {
// guard against listeners being updated by a listener
TaskListener[] ll = this.listeners;
for (TaskListener l: ll)
l.finished(e);
}
示例10: setTaskListener
import com.sun.source.util.TaskListener; //导入依赖的package包/类
@Override
public void setTaskListener(TaskListener tl) {
MultiTaskListener mtl = MultiTaskListener.instance(context);
if (taskListener != null)
mtl.remove(taskListener);
if (tl != null)
mtl.add(tl);
taskListener = tl;
}
示例11: remove
import com.sun.source.util.TaskListener; //导入依赖的package包/类
public void remove(TaskListener listener) {
for (int i = 0; i < listeners.length; i++) {
if (ccw.unwrap(listeners[i]) == listener) {
if (listeners.length == 1) {
listeners = EMPTY_LISTENERS;
} else {
TaskListener[] newListeners = new TaskListener[listeners.length - 1];
System.arraycopy(listeners, 0, newListeners, 0, i);
System.arraycopy(listeners, i + 1, newListeners, i, newListeners.length - i);
listeners = newListeners;
}
break;
}
}
}
示例12: started
import com.sun.source.util.TaskListener; //导入依赖的package包/类
@Override @DefinedBy(Api.COMPILER_TREE)
public void started(TaskEvent e) {
// guard against listeners being updated by a listener
TaskListener[] ll = this.listeners;
for (TaskListener l: ll)
l.started(e);
}
示例13: finished
import com.sun.source.util.TaskListener; //导入依赖的package包/类
@Override @DefinedBy(Api.COMPILER_TREE)
public void finished(TaskEvent e) {
// guard against listeners being updated by a listener
TaskListener[] ll = this.listeners;
for (TaskListener l: ll)
l.finished(e);
}
示例14: setTaskListener
import com.sun.source.util.TaskListener; //导入依赖的package包/类
@Override @DefinedBy(Api.COMPILER_TREE)
public void setTaskListener(TaskListener tl) {
MultiTaskListener mtl = MultiTaskListener.instance(context);
if (taskListener != null)
mtl.remove(taskListener);
if (tl != null)
mtl.add(tl);
taskListener = tl;
}