1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/test/tools/javac/T6358168.java Sat Dec 01 00:00:00 2007 +0000 1.3 @@ -0,0 +1,113 @@ 1.4 +/* 1.5 + * Copyright 2006 Sun Microsystems, Inc. All Rights Reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 1.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 1.24 + * have any questions. 1.25 + */ 1.26 + 1.27 +/* 1.28 + * @test 1.29 + * @bug 6358168 1.30 + * @summary JavaCompiler.hasBeenUsed is not set in delegateCompiler 1.31 + */ 1.32 + 1.33 +import java.io.*; 1.34 +import java.net.*; 1.35 +import java.util.*; 1.36 +import javax.annotation.processing.*; 1.37 +import javax.lang.model.element.*; 1.38 +import javax.tools.*; 1.39 +import com.sun.tools.javac.main.JavaCompiler; 1.40 +import com.sun.tools.javac.main.*; 1.41 +import com.sun.tools.javac.util.*; 1.42 +import com.sun.tools.javac.util.List; // disambiguate 1.43 + 1.44 + 1.45 +@SupportedAnnotationTypes("*") 1.46 +public class T6358168 extends AbstractProcessor { 1.47 + private static String testClasses = System.getProperty("test.classes"); 1.48 + private static String testSrc = System.getProperty("test.src"); 1.49 + private static String self = T6358168.class.getName(); 1.50 + 1.51 + public static void main(String... args) throws Throwable { 1.52 + 1.53 + JavacFileManager fm = new JavacFileManager(new Context(), false, null); 1.54 + JavaFileObject f = fm.getFileForInput(testSrc + File.separatorChar + T6358168.class.getName() + ".java"); 1.55 + 1.56 + try { 1.57 + // first, test case with no annotation processing 1.58 + testNoAnnotationProcessing(fm, f); 1.59 + 1.60 + // now, test case with annotation processing 1.61 + testAnnotationProcessing(fm, f); 1.62 + } 1.63 + catch (Throwable t) { 1.64 + AssertionError e = new AssertionError(); 1.65 + e.initCause(t); 1.66 + throw e; 1.67 + } 1.68 + } 1.69 + 1.70 + static void testNoAnnotationProcessing(JavacFileManager fm, JavaFileObject f) throws Throwable { 1.71 + Context context = new Context(); 1.72 + fm.setContext(context); 1.73 + 1.74 + Main compilerMain = new Main("javac", new PrintWriter(System.err, true)); 1.75 + compilerMain.setOptions(Options.instance(context)); 1.76 + compilerMain.filenames = new ListBuffer<File>(); 1.77 + compilerMain.processArgs(new String[] { "-d", "." }); 1.78 + 1.79 + JavaCompiler compiler = JavaCompiler.instance(context); 1.80 + compiler.compile(List.of(f)); 1.81 + try { 1.82 + compiler.compile(List.of(f)); 1.83 + throw new Error("Error: AssertionError not thrown after second call of compile"); 1.84 + } catch (AssertionError e) { 1.85 + System.err.println("Exception from compiler (expected): " + e); 1.86 + } 1.87 + } 1.88 + 1.89 + static void testAnnotationProcessing(JavacFileManager fm, JavaFileObject f) throws Throwable { 1.90 + Context context = new Context(); 1.91 + fm.setContext(context); 1.92 + 1.93 + Main compilerMain = new Main("javac", new PrintWriter(System.err, true)); 1.94 + compilerMain.setOptions(Options.instance(context)); 1.95 + compilerMain.filenames = new ListBuffer<File>(); 1.96 + compilerMain.processArgs(new String[] { 1.97 + "-XprintRounds", 1.98 + "-processorpath", testClasses, 1.99 + "-processor", self, 1.100 + "-d", "."}); 1.101 + 1.102 + JavaCompiler compiler = JavaCompiler.instance(context); 1.103 + compiler.initProcessAnnotations(null); 1.104 + JavaCompiler compiler2 = compiler.processAnnotations(compiler.enterTrees(compiler.parseFiles(List.of(f)))); 1.105 + try { 1.106 + compiler2.compile(List.of(f)); 1.107 + throw new Error("Error: AssertionError not thrown after second call of compile"); 1.108 + } catch (AssertionError e) { 1.109 + System.err.println("Exception from compiler (expected): " + e); 1.110 + } 1.111 + } 1.112 + 1.113 + public boolean process(Set<? extends TypeElement> tes, RoundEnvironment renv) { 1.114 + return true; 1.115 + } 1.116 +}