test/tools/javac/T6358168.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 6358168
    27  * @summary JavaCompiler.hasBeenUsed is not set in delegateCompiler
    28  */
    30 import java.io.*;
    31 import java.net.*;
    32 import java.util.*;
    33 import javax.annotation.processing.*;
    34 import javax.lang.model.element.*;
    35 import javax.tools.*;
    36 import com.sun.tools.javac.file.*;
    37 import com.sun.tools.javac.file.JavacFileManager;
    38 import com.sun.tools.javac.main.JavaCompiler;
    39 import com.sun.tools.javac.main.*;
    40 import com.sun.tools.javac.util.*;
    41 import com.sun.tools.javac.util.List; // disambiguate
    44 @SupportedAnnotationTypes("*")
    45 public class T6358168 extends AbstractProcessor {
    46     private static String testClasses = System.getProperty("test.classes");
    47     private static String testSrc = System.getProperty("test.src");
    48     private static String self = T6358168.class.getName();
    50     public static void main(String... args) throws Throwable {
    52         JavacFileManager fm = new JavacFileManager(new Context(), false, null);
    53         JavaFileObject f = fm.getFileForInput(testSrc + File.separatorChar + T6358168.class.getName() + ".java");
    55         try {
    56             // first, test case with no annotation processing
    57             testNoAnnotationProcessing(fm, f);
    59             // now, test case with annotation processing
    60             testAnnotationProcessing(fm, f);
    61         }
    62         catch (Throwable t) {
    63             AssertionError e = new AssertionError();
    64             e.initCause(t);
    65             throw e;
    66         }
    67     }
    69     static void testNoAnnotationProcessing(JavacFileManager fm, JavaFileObject f) throws Throwable {
    70         Context context = new Context();
    71         fm.setContext(context);
    73         Main compilerMain = new Main("javac", new PrintWriter(System.err, true));
    74         compilerMain.setOptions(Options.instance(context));
    75         compilerMain.filenames = new ListBuffer<File>();
    76         compilerMain.processArgs(new String[] { "-d", "." });
    78         JavaCompiler compiler = JavaCompiler.instance(context);
    79         compiler.compile(List.of(f));
    80         try {
    81             compiler.compile(List.of(f));
    82             throw new Error("Error: AssertionError not thrown after second call of compile");
    83         } catch (AssertionError e) {
    84             System.err.println("Exception from compiler (expected): " + e);
    85         }
    86     }
    88     static void testAnnotationProcessing(JavacFileManager fm, JavaFileObject f) throws Throwable {
    89         Context context = new Context();
    90         fm.setContext(context);
    92         Main compilerMain = new Main("javac", new PrintWriter(System.err, true));
    93         compilerMain.setOptions(Options.instance(context));
    94         compilerMain.filenames = new ListBuffer<File>();
    95         compilerMain.processArgs(new String[] {
    96                                      "-XprintRounds",
    97                                      "-processorpath", testClasses,
    98                                      "-processor", self,
    99                                      "-d", "."});
   101         JavaCompiler compiler = JavaCompiler.instance(context);
   102         compiler.initProcessAnnotations(null);
   103         JavaCompiler compiler2 = compiler.processAnnotations(compiler.enterTrees(compiler.parseFiles(List.of(f))));
   104         try {
   105             compiler2.compile(List.of(f));
   106             throw new Error("Error: AssertionError not thrown after second call of compile");
   107         } catch (AssertionError e) {
   108             System.err.println("Exception from compiler (expected): " + e);
   109         }
   110     }
   112     public boolean process(Set<? extends TypeElement> tes, RoundEnvironment renv) {
   113         return true;
   114     }
   115 }

mercurial