1203N/A/*
1203N/A * Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved.
1203N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1203N/A *
1203N/A * This code is free software; you can redistribute it and/or modify it
1203N/A * under the terms of the GNU General Public License version 2 only, as
1203N/A * published by the Free Software Foundation.
1203N/A *
1203N/A * This code is distributed in the hope that it will be useful, but WITHOUT
1203N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1203N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
1203N/A * version 2 for more details (a copy is included in the LICENSE file that
1203N/A * accompanied this code).
1203N/A *
1203N/A * You should have received a copy of the GNU General Public License version
1203N/A * 2 along with this work; if not, write to the Free Software Foundation,
1203N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1203N/A *
1203N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1203N/A * or visit www.oracle.com if you need additional information or have any
1203N/A * questions.
1203N/A */
1203N/A
1203N/A/*
1203N/A * @test
1203N/A * @bug 7159016
1203N/A * @summary Static import of member in processor-generated class fails in JDK 7
1203N/A * @library lib
1203N/A * @build JavacTestingAbstractProcessor
1203N/A * @run main T7159016
1203N/A * @author Jesse Glick
1203N/A */
1203N/A
1203N/Aimport java.io.File;
1203N/Aimport java.io.FileWriter;
1203N/Aimport java.io.IOException;
1203N/Aimport java.io.Writer;
1203N/Aimport java.util.Collections;
1203N/Aimport java.util.Set;
1203N/Aimport javax.annotation.processing.AbstractProcessor;
1203N/Aimport javax.annotation.processing.RoundEnvironment;
1203N/Aimport javax.annotation.processing.SupportedAnnotationTypes;
1203N/Aimport javax.annotation.processing.SupportedSourceVersion;
1203N/Aimport javax.lang.model.SourceVersion;
1203N/Aimport javax.lang.model.element.TypeElement;
1203N/Aimport javax.tools.Diagnostic;
1203N/Aimport javax.tools.JavaCompiler;
1203N/Aimport javax.tools.ToolProvider;
1203N/A
1203N/Apublic class T7159016 {
1203N/A public static void main(String[] args) throws Exception {
1203N/A File src = new File("C.java");
1203N/A Writer w = new FileWriter(src);
1203N/A try {
1203N/A w.write("import static p.Generated.m;\nclass C { {m(); } }\n");
1203N/A w.flush();
1203N/A } finally {
1203N/A w.close();
1203N/A }
1203N/A JavaCompiler jc = ToolProvider.getSystemJavaCompiler();
1203N/A JavaCompiler.CompilationTask task = jc.getTask(null, null, null, null, null,
1203N/A jc.getStandardFileManager(null, null, null).getJavaFileObjects(src));
1203N/A task.setProcessors(Collections.singleton(new Proc()));
1203N/A if (!task.call()) {
1203N/A throw new Error("Test failed");
1203N/A }
1203N/A }
1203N/A
1203N/A private static class Proc extends JavacTestingAbstractProcessor {
1203N/A int written;
1203N/A @Override public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
1203N/A if (roundEnv.processingOver() || written++ > 0) {
1203N/A return false;
1203N/A }
1203N/A messager.printMessage(Diagnostic.Kind.NOTE, "writing Generated.java");
1203N/A try {
1203N/A Writer w = processingEnv.getFiler().createSourceFile("p.Generated").openWriter();
1203N/A try {
1203N/A w.write("package p; public class Generated { public static void m() { } }");
1203N/A } finally {
1203N/A w.close();
1203N/A }
1203N/A } catch (IOException x) {
1203N/A messager.printMessage(Diagnostic.Kind.ERROR, x.toString());
1203N/A }
1203N/A return true;
1203N/A }
1203N/A }
1203N/A}