Java Code Examples for com.sun.source.util.JavacTask#addTaskListener()

The following examples show how to use com.sun.source.util.JavacTask#addTaskListener() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestSimpleAddRemove.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@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;
        }
 
Example 2
Source File: ComboTask.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example 3
Source File: TestSimpleAddRemove.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
@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;
        }
 
Example 4
Source File: TestSimpleAddRemove.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
@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;
        }
 
Example 5
Source File: CodingRulesAnalyzerPlugin.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@DefinedBy(Api.COMPILER_TREE)
public void init(JavacTask task, String... args) {
    BasicJavacTask impl = (BasicJavacTask)task;
    Context context = impl.getContext();
    log = Log.instance(context);
    trees = Trees.instance(task);
    task.addTaskListener(new PostAnalyzeTaskListener(
            new MutableFieldsAnalyzer(task),
            new AssertCheckAnalyzer(task),
            new DefinedByAnalyzer(task)
    ));
}
 
Example 6
Source File: AbstractCodingRulesAnalyzer.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public void init(JavacTask task, String... args) {
    BasicJavacTask impl = (BasicJavacTask)task;
    Context context = impl.getContext();
    log = Log.instance(context);
    trees = Trees.instance(task);
    messages = new Messages();
    task.addTaskListener(new PostAnalyzeTaskListener());
}
 
Example 7
Source File: Test.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
void testTaskListener(JavacTool javac, StandardJavaFileManager fm,
        Iterable<? extends JavaFileObject> files, PrintWriter out,
        int expectedDocComments) {
    out.println("Test task listener");
    JavacTask task = javac.getTask(out, fm, null, null, null, files);
    TaskListnr tl = new TaskListnr(DocTrees.instance(task));
    task.addTaskListener(tl);
    task.call();
    tl.checker.checkDocComments(expectedDocComments);
}
 
Example 8
Source File: AbstractCodingRulesAnalyzer.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public void init(JavacTask task, String... args) {
    BasicJavacTask impl = (BasicJavacTask)task;
    Context context = impl.getContext();
    log = Log.instance(context);
    trees = Trees.instance(task);
    messages = new Messages();
    task.addTaskListener(new PostAnalyzeTaskListener());
}
 
Example 9
Source File: Test.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
void testTaskListener(JavacTool javac, StandardJavaFileManager fm,
        Iterable<? extends JavaFileObject> files, PrintWriter out,
        int expectedDocComments) {
    out.println("Test task listener");
    JavacTask task = javac.getTask(out, fm, null, null, null, files);
    TaskListnr tl = new TaskListnr(DocTrees.instance(task));
    task.addTaskListener(tl);
    task.call();
    tl.checker.checkDocComments(expectedDocComments);
}
 
Example 10
Source File: AbstractCodingRulesAnalyzer.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public void init(JavacTask task, String... args) {
    BasicJavacTask impl = (BasicJavacTask)task;
    Context context = impl.getContext();
    log = Log.instance(context);
    trees = Trees.instance(task);
    messages = new Messages();
    task.addTaskListener(new PostAnalyzeTaskListener());
}
 
Example 11
Source File: Test.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
void testTaskListener(JavacTool javac, StandardJavaFileManager fm,
        Iterable<? extends JavaFileObject> files, PrintWriter out,
        int expectedDocComments) {
    out.println("Test task listener");
    JavacTask task = javac.getTask(out, fm, null, null, null, files);
    TaskListnr tl = new TaskListnr(DocTrees.instance(task));
    task.addTaskListener(tl);
    task.call();
    tl.checker.checkDocComments(expectedDocComments);
}
 
Example 12
Source File: AbstractCodingRulesAnalyzer.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public void init(JavacTask task, String... args) {
    BasicJavacTask impl = (BasicJavacTask)task;
    Context context = impl.getContext();
    log = Log.instance(context);
    trees = Trees.instance(task);
    messages = new Messages();
    task.addTaskListener(new PostAnalyzeTaskListener());
}
 
Example 13
Source File: Test.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
void testTaskListener(JavacTool javac, StandardJavaFileManager fm,
        Iterable<? extends JavaFileObject> files, PrintWriter out,
        int expectedDocComments) {
    out.println("Test task listener");
    JavacTask task = javac.getTask(out, fm, null, null, null, files);
    TaskListnr tl = new TaskListnr(DocTrees.instance(task));
    task.addTaskListener(tl);
    task.call();
    tl.checker.checkDocComments(expectedDocComments);
}
 
Example 14
Source File: Test.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
void testTaskListener(JavacTool javac, StandardJavaFileManager fm,
        Iterable<? extends JavaFileObject> files, PrintWriter out,
        int expectedDocComments) {
    out.println("Test task listener");
    JavacTask task = javac.getTask(out, fm, null, null, null, files);
    TaskListnr tl = new TaskListnr(DocTrees.instance(task));
    task.addTaskListener(tl);
    task.call();
    tl.checker.checkDocComments(expectedDocComments);
}
 
Example 15
Source File: ShowTypePlugin.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public void init(JavacTask task, String... args) {
    Pattern pattern = null;
    if (args.length == 1)
        pattern = Pattern.compile(args[0]);
    task.addTaskListener(new PostAnalyzeTaskListener(task, pattern));
}
 
Example 16
Source File: ShowTypePlugin.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public void init(JavacTask task, String... args) {
    Pattern pattern = null;
    if (args.length == 1)
        pattern = Pattern.compile(args[0]);
    task.addTaskListener(new PostAnalyzeTaskListener(task, pattern));
}
 
Example 17
Source File: ShowTypePlugin.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
public void init(JavacTask task, String... args) {
    Pattern pattern = null;
    if (args.length == 1)
        pattern = Pattern.compile(args[0]);
    task.addTaskListener(new PostAnalyzeTaskListener(task, pattern));
}
 
Example 18
Source File: TestSimpleAddRemove.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
void test(CompileKind ck, AddKind ak, RemoveKind rk) throws IOException {
    System.err.println("Test: " + ck + " " + ak + " " + rk);

    File tmpDir = new File(ck + "-" + ak + "-" + rk);
    tmpDir.mkdirs();
    fm.setLocation(StandardLocation.CLASS_OUTPUT, Arrays.asList(tmpDir));

    List<String> options = new ArrayList<String>();
    Iterable<? extends JavaFileObject> files = Arrays.asList(new TestSource());
    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);
    JavacTask task = tool.getTask(pw, fm, null, options, null, files);

    EventKindCounter ec = new EventKindCounter();
    TaskListener listener = new TestListener(ec);
    boolean needProcessor = false;

    switch (ak) {
        case SET_IN_TASK:
            task.setTaskListener(listener);
            break;
        case ADD_IN_TASK:
            task.addTaskListener(listener);
            break;
        case ADD_IN_PROCESSOR:
        case ADD_IN_LISTENER:
            needProcessor = true;
    }

    switch (rk) {
        case REMOVE_IN_TASK:
            task.removeTaskListener(listener);
            break;
        case REMOVE_IN_PROCESSOR:
        case REMOVE_IN_LISTENER:
            needProcessor = true;
    }

    if (needProcessor)
        task.setProcessors(Arrays.asList(new TestProcessor(ak, rk, listener)));

    ck.run(task);
    System.err.println(ec);

    check(ck, ak, rk, ec);

    System.err.println();
}
 
Example 19
Source File: ShowTypePlugin.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
public void init(JavacTask task, String... args) {
    Pattern pattern = null;
    if (args.length == 1)
        pattern = Pattern.compile(args[0]);
    task.addTaskListener(new PostAnalyzeTaskListener(task, pattern));
}
 
Example 20
Source File: TestSimpleAddRemove.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
void test(CompileKind ck, AddKind ak, RemoveKind rk) throws IOException {
    System.err.println("Test: " + ck + " " + ak + " " + rk);

    File tmpDir = new File(ck + "-" + ak + "-" + rk);
    tmpDir.mkdirs();
    fm.setLocation(StandardLocation.CLASS_OUTPUT, Arrays.asList(tmpDir));

    List<String> options = new ArrayList<String>();
    Iterable<? extends JavaFileObject> files = Arrays.asList(new TestSource());
    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);
    JavacTask task = tool.getTask(pw, fm, null, options, null, files);

    EventKindCounter ec = new EventKindCounter();
    TaskListener listener = new TestListener(ec);
    boolean needProcessor = false;

    switch (ak) {
        case SET_IN_TASK:
            task.setTaskListener(listener);
            break;
        case ADD_IN_TASK:
            task.addTaskListener(listener);
            break;
        case ADD_IN_PROCESSOR:
        case ADD_IN_LISTENER:
            needProcessor = true;
    }

    switch (rk) {
        case REMOVE_IN_TASK:
            task.removeTaskListener(listener);
            break;
        case REMOVE_IN_PROCESSOR:
        case REMOVE_IN_LISTENER:
            needProcessor = true;
    }

    if (needProcessor)
        task.setProcessors(Arrays.asList(new TestProcessor(ak, rk, listener)));

    ck.run(task);
    System.err.println(ec);

    check(ck, ak, rk, ec);

    System.err.println();
}