test/tools/javac/processing/T6920317.java

Print this page




   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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25  * @test
  26  * @bug 6920317
  27  * @summary package-info.java file has to be specified on the javac cmdline, else it will not be avail

  28  */
  29 
  30 import java.io.*;
  31 import java.util.*;
  32 import javax.annotation.processing.*;
  33 import javax.lang.model.*;
  34 import javax.lang.model.element.*;
  35 import javax.lang.model.util.*;
  36 import javax.tools.*;
  37 
  38 /**
  39  * The test exercises different ways of providing annotations for a package.
  40  * Each way provides an annotation with a unique argument. For each test
  41  * case, the test verifies that the annotation with the correct argument is
  42  * found by the compiler.
  43  */
  44 public class T6920317 {
  45     public static void main(String... args) throws Exception {
  46         new T6920317().run(args);
  47     }


 332 
 333     /** Number of errors found. */
 334     int errors;
 335 
 336     /** Optional set of test cases to be run; empty implies all test cases. */
 337     Set<Integer> tests = new HashSet<Integer>();
 338 
 339     /*  Files created by setup. */
 340     File test_java;
 341     File sp_old;
 342     File sp_new;
 343     File sp_gen;
 344     File cp_old;
 345     File cp_new;
 346     File cp_gen;
 347     File cl_pkgInfo_java;
 348 
 349     /** Annotation processor used to verify the expected value for the
 350         package annotations found by javac. */
 351     @SupportedOptions({ "gen", "expect" })
 352     @SupportedAnnotationTypes({"*"})
 353     public static class Processor extends AbstractProcessor {
 354         public SourceVersion getSupportedSourceVersion() {
 355             return SourceVersion.latest();
 356         }
 357 
 358         public boolean process(Set<? extends TypeElement> annots, RoundEnvironment renv) {
 359             round++;
 360             System.err.println("Round " + round + " annots:" + annots + " rootElems:" + renv.getRootElements());
 361 
 362             // if this is the first round and the gen option is given, use the filer to create
 363             // a copy of the file specified by the gen option.
 364             String gen = getOption("gen");
 365             if (round == 1 && gen != null) {
 366                 try {
 367                     Filer filer = processingEnv.getFiler();
 368                     JavaFileObject f;
 369                     if (gen.endsWith(".java"))
 370                         f = filer.createSourceFile("p.package-info");
 371                     else
 372                         f = filer.createClassFile("p.package-info");
 373                     System.err.println("copy " + gen + " to " + f.getName());
 374                     write(f, read(new File(gen)));
 375                 } catch (IOException e) {
 376                     error("Cannot create package-info file: " + e);
 377                 }




   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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25  * @test
  26  * @bug 6920317
  27  * @summary package-info.java file has to be specified on the javac cmdline, else it will not be avail
  28  * @library ../lib
  29  */
  30 
  31 import java.io.*;
  32 import java.util.*;
  33 import javax.annotation.processing.*;
  34 import javax.lang.model.*;
  35 import javax.lang.model.element.*;
  36 import javax.lang.model.util.*;
  37 import javax.tools.*;
  38 
  39 /**
  40  * The test exercises different ways of providing annotations for a package.
  41  * Each way provides an annotation with a unique argument. For each test
  42  * case, the test verifies that the annotation with the correct argument is
  43  * found by the compiler.
  44  */
  45 public class T6920317 {
  46     public static void main(String... args) throws Exception {
  47         new T6920317().run(args);
  48     }


 333 
 334     /** Number of errors found. */
 335     int errors;
 336 
 337     /** Optional set of test cases to be run; empty implies all test cases. */
 338     Set<Integer> tests = new HashSet<Integer>();
 339 
 340     /*  Files created by setup. */
 341     File test_java;
 342     File sp_old;
 343     File sp_new;
 344     File sp_gen;
 345     File cp_old;
 346     File cp_new;
 347     File cp_gen;
 348     File cl_pkgInfo_java;
 349 
 350     /** Annotation processor used to verify the expected value for the
 351         package annotations found by javac. */
 352     @SupportedOptions({ "gen", "expect" })
 353     public static class Processor extends JavacTestingAbstractProcessor {





 354         public boolean process(Set<? extends TypeElement> annots, RoundEnvironment renv) {
 355             round++;
 356             System.err.println("Round " + round + " annots:" + annots + " rootElems:" + renv.getRootElements());
 357 
 358             // if this is the first round and the gen option is given, use the filer to create
 359             // a copy of the file specified by the gen option.
 360             String gen = getOption("gen");
 361             if (round == 1 && gen != null) {
 362                 try {
 363                     Filer filer = processingEnv.getFiler();
 364                     JavaFileObject f;
 365                     if (gen.endsWith(".java"))
 366                         f = filer.createSourceFile("p.package-info");
 367                     else
 368                         f = filer.createClassFile("p.package-info");
 369                     System.err.println("copy " + gen + " to " + f.getName());
 370                     write(f, read(new File(gen)));
 371                 } catch (IOException e) {
 372                     error("Cannot create package-info file: " + e);
 373                 }