T6358168.java revision 57
0N/A/*
2362N/A * Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
2362N/A * CA 95054 USA or visit www.sun.com if you need additional information or
2362N/A * have any questions.
0N/A */
0N/A
0N/A/*
0N/A * @test
0N/A * @bug 6358168
0N/A * @summary JavaCompiler.hasBeenUsed is not set in delegateCompiler
0N/A */
0N/A
0N/Aimport java.io.*;
0N/Aimport java.net.*;
0N/Aimport java.util.*;
0N/Aimport javax.annotation.processing.*;
0N/Aimport javax.lang.model.element.*;
0N/Aimport javax.tools.*;
0N/Aimport com.sun.tools.javac.file.*;
0N/Aimport com.sun.tools.javac.file.JavacFileManager;
0N/Aimport com.sun.tools.javac.main.JavaCompiler;
0N/Aimport com.sun.tools.javac.main.*;
0N/Aimport com.sun.tools.javac.util.*;
0N/Aimport com.sun.tools.javac.util.List; // disambiguate
0N/A
0N/A
0N/A@SupportedAnnotationTypes("*")
0N/Apublic class T6358168 extends AbstractProcessor {
0N/A private static String testClasses = System.getProperty("test.classes");
0N/A private static String testSrc = System.getProperty("test.src");
0N/A private static String self = T6358168.class.getName();
0N/A
0N/A public static void main(String... args) throws Throwable {
0N/A
0N/A JavacFileManager fm = new JavacFileManager(new Context(), false, null);
0N/A JavaFileObject f = fm.getFileForInput(testSrc + File.separatorChar + T6358168.class.getName() + ".java");
0N/A
0N/A try {
0N/A // first, test case with no annotation processing
0N/A testNoAnnotationProcessing(fm, f);
0N/A
0N/A // now, test case with annotation processing
0N/A testAnnotationProcessing(fm, f);
0N/A }
0N/A catch (Throwable t) {
0N/A AssertionError e = new AssertionError();
0N/A e.initCause(t);
0N/A throw e;
0N/A }
0N/A }
0N/A
0N/A static void testNoAnnotationProcessing(JavacFileManager fm, JavaFileObject f) throws Throwable {
0N/A Context context = new Context();
0N/A fm.setContext(context);
0N/A
0N/A Main compilerMain = new Main("javac", new PrintWriter(System.err, true));
0N/A compilerMain.setOptions(Options.instance(context));
0N/A compilerMain.filenames = new ListBuffer<File>();
0N/A compilerMain.processArgs(new String[] { "-d", "." });
0N/A
0N/A JavaCompiler compiler = JavaCompiler.instance(context);
0N/A compiler.compile(List.of(f));
0N/A try {
0N/A compiler.compile(List.of(f));
0N/A throw new Error("Error: AssertionError not thrown after second call of compile");
0N/A } catch (AssertionError e) {
0N/A System.err.println("Exception from compiler (expected): " + e);
0N/A }
0N/A }
0N/A
0N/A static void testAnnotationProcessing(JavacFileManager fm, JavaFileObject f) throws Throwable {
0N/A Context context = new Context();
0N/A fm.setContext(context);
0N/A
0N/A Main compilerMain = new Main("javac", new PrintWriter(System.err, true));
0N/A compilerMain.setOptions(Options.instance(context));
0N/A compilerMain.filenames = new ListBuffer<File>();
0N/A compilerMain.processArgs(new String[] {
0N/A "-XprintRounds",
0N/A "-processorpath", testClasses,
0N/A "-processor", self,
0N/A "-d", "."});
0N/A
0N/A JavaCompiler compiler = JavaCompiler.instance(context);
0N/A compiler.initProcessAnnotations(null);
0N/A JavaCompiler compiler2 = compiler.processAnnotations(compiler.enterTrees(compiler.parseFiles(List.of(f))));
0N/A try {
0N/A compiler2.compile(List.of(f));
0N/A throw new Error("Error: AssertionError not thrown after second call of compile");
0N/A } catch (AssertionError e) {
0N/A System.err.println("Exception from compiler (expected): " + e);
0N/A }
0N/A }
0N/A
0N/A public boolean process(Set<? extends TypeElement> tes, RoundEnvironment renv) {
0N/A return true;
0N/A }
0N/A}
0N/A