当前位置: 首页>>代码示例>>Java>>正文


Java TaskListener类代码示例

本文整理汇总了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();
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:22,代码来源:TestClose.java

示例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;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:31,代码来源:ComboTask.java

示例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();
    }
}
 
开发者ID:ojdkbuild,项目名称:lookaside_java-1.8.0-openjdk,代码行数:21,代码来源:TestClose.java

示例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));
    }
}
 
开发者ID:unktomi,项目名称:form-follows-function,代码行数:25,代码来源:JavacProcessingEnvironment.java

示例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();
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:28,代码来源:JavacProcessingEnvironment.java

示例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);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:9,代码来源:MultiTaskListener.java

示例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;
        }
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:12,代码来源:MultiTaskListener.java

示例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);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:8,代码来源:MultiTaskListener.java

示例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);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:8,代码来源:MultiTaskListener.java

示例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;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:10,代码来源:BasicJavacTask.java

示例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;
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:16,代码来源:MultiTaskListener.java

示例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);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:8,代码来源:MultiTaskListener.java

示例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);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:8,代码来源:MultiTaskListener.java

示例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;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:10,代码来源:BasicJavacTask.java


注:本文中的com.sun.source.util.TaskListener类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。