test/tools/javac/T6358024.java

Fri, 04 Jul 2008 15:06:27 -0700

author
tbell
date
Fri, 04 Jul 2008 15:06:27 -0700
changeset 62
07c916ecfc71
parent 58
8bc2ca2a3b0a
parent 54
eaf608c64fec
child 554
9d9f26857129
permissions
-rw-r--r--

Merge

     1 /*
     2  * Copyright 2006-2008 Sun Microsystems, Inc.  All Rights Reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     8  *
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    12  * version 2 for more details (a copy is included in the LICENSE file that
    13  * accompanied this code).
    14  *
    15  * You should have received a copy of the GNU General Public License version
    16  * 2 along with this work; if not, write to the Free Software Foundation,
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    18  *
    19  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    20  * CA 95054 USA or visit www.sun.com if you need additional information or
    21  * have any questions.
    22  */
    24 /*
    25  * @test
    26  * @bug 6358024
    27  * @summary TaskListener should be propogated between processing rounds
    28  */
    30 import java.io.*;
    31 import java.util.*;
    32 import java.util.List;
    33 import javax.annotation.processing.*;
    34 import javax.lang.model.element.*;
    35 import javax.tools.*;
    36 import com.sun.source.util.*;
    37 import com.sun.tools.javac.api.*;
    38 import com.sun.tools.javac.file.*;
    39 import com.sun.tools.javac.file.JavacFileManager;
    40 import com.sun.tools.javac.main.*;
    41 import com.sun.tools.javac.util.*;
    44 @SupportedAnnotationTypes("*")
    45 public class T6358024 extends AbstractProcessor {
    46     static JavacFileManager fm;
    47     public static void main(String... args) throws Throwable {
    48         String self = T6358024.class.getName();
    50         String testSrc = System.getProperty("test.src");
    52         fm = new JavacFileManager(new Context(), false, null);
    53         JavaFileObject f = fm.getFileForInput(testSrc + File.separatorChar + self + ".java");
    55         test(fm, f,
    56              new Option[] { new Option("-d", ".")},
    57              7);
    59         test(fm, f,
    60              new Option[] { new XOption("-XprintRounds"),
    61                             new Option("-processorpath", "."),
    62                             new Option("-processor", self) },
    63              11);
    64     }
    66     static void test(JavacFileManager fm, JavaFileObject f, Option[] opts, int expect) throws Throwable {
    67         PrintWriter out = new PrintWriter(System.err, true);
    69         JavacTool tool = JavacTool.create();
    70         List<String> flags = new ArrayList<String>();
    71         for (Option opt: opts) {
    72             flags.add(opt.name);
    73             for (Object arg : opt.args)
    74                 flags.add(arg.toString());
    75         }
    77         JavacTaskImpl task = (JavacTaskImpl) tool.getTask(out,
    78                                                           fm,
    79                                                           null,
    80                                                           flags,
    81                                                           null,
    82                                                           Arrays.asList(f));
    83         MyTaskListener tl = new MyTaskListener();
    84         task.setTaskListener(tl);
    85         task.call();
    86         if (tl.started != expect)
    87             throw new AssertionError("Unexpected number of TaskListener events; "
    88                                      + "expected " + expect + ", found " + tl.started);
    89     }
    91     public boolean process(Set<? extends TypeElement> tes, RoundEnvironment renv) {
    92         return true;
    93     }
    95     static class MyTaskListener implements TaskListener {
    96         public void started(TaskEvent e) {
    97             System.err.println("Started: " + e);
    98             started++;
    99         }
   100         public void finished(TaskEvent e) {
   101         }
   103         int started = 0;
   104     }
   106     static class Option {
   107         Option(String name, String... args) {
   108             this.name = name;
   109             this.args = args;
   110         }
   111         public final String name;
   112         public final String[] args;
   113     }
   115     static class XOption extends Option {
   116         XOption(String name, String... args) {
   117             super(name, args);
   118         }
   119     }
   120 }

mercurial