langtools/test/tools/javac/T7159016.java
author katleman
Thu, 21 Aug 2014 14:16:14 -0700
changeset 25878 6d561031123e
parent 12917 0c381f0ac967
child 27319 030080f03e4f
permissions -rw-r--r--
Added tag jdk9-b27 for changeset 98ce0879ab4c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12917
0c381f0ac967 7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff changeset
     1
/*
0c381f0ac967 7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff changeset
     2
 * Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved.
0c381f0ac967 7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0c381f0ac967 7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff changeset
     4
 *
0c381f0ac967 7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
0c381f0ac967 7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
0c381f0ac967 7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff changeset
     7
 * published by the Free Software Foundation.
0c381f0ac967 7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff changeset
     8
 *
0c381f0ac967 7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
0c381f0ac967 7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0c381f0ac967 7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
0c381f0ac967 7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
0c381f0ac967 7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff changeset
    13
 * accompanied this code).
0c381f0ac967 7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff changeset
    14
 *
0c381f0ac967 7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
0c381f0ac967 7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
0c381f0ac967 7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0c381f0ac967 7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff changeset
    18
 *
0c381f0ac967 7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
0c381f0ac967 7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
0c381f0ac967 7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff changeset
    21
 * questions.
0c381f0ac967 7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff changeset
    22
 */
0c381f0ac967 7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff changeset
    23
0c381f0ac967 7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff changeset
    24
/*
0c381f0ac967 7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff changeset
    25
 * @test
0c381f0ac967 7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff changeset
    26
 * @bug 7159016
0c381f0ac967 7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff changeset
    27
 * @summary Static import of member in processor-generated class fails in JDK 7
0c381f0ac967 7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff changeset
    28
 * @library lib
0c381f0ac967 7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff changeset
    29
 * @build JavacTestingAbstractProcessor
0c381f0ac967 7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff changeset
    30
 * @run main T7159016
0c381f0ac967 7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff changeset
    31
 * @author Jessie Glick
0c381f0ac967 7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff changeset
    32
 */
0c381f0ac967 7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff changeset
    33
0c381f0ac967 7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff changeset
    34
import java.io.File;
0c381f0ac967 7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff changeset
    35
import java.io.FileWriter;
0c381f0ac967 7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff changeset
    36
import java.io.IOException;
0c381f0ac967 7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff changeset
    37
import java.io.Writer;
0c381f0ac967 7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff changeset
    38
import java.util.Collections;
0c381f0ac967 7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff changeset
    39
import java.util.Set;
0c381f0ac967 7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff changeset
    40
import javax.annotation.processing.AbstractProcessor;
0c381f0ac967 7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff changeset
    41
import javax.annotation.processing.RoundEnvironment;
0c381f0ac967 7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff changeset
    42
import javax.annotation.processing.SupportedAnnotationTypes;
0c381f0ac967 7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff changeset
    43
import javax.annotation.processing.SupportedSourceVersion;
0c381f0ac967 7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff changeset
    44
import javax.lang.model.SourceVersion;
0c381f0ac967 7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff changeset
    45
import javax.lang.model.element.TypeElement;
0c381f0ac967 7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff changeset
    46
import javax.tools.Diagnostic;
0c381f0ac967 7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff changeset
    47
import javax.tools.JavaCompiler;
0c381f0ac967 7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff changeset
    48
import javax.tools.ToolProvider;
0c381f0ac967 7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff changeset
    49
0c381f0ac967 7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff changeset
    50
public class T7159016 {
0c381f0ac967 7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff changeset
    51
    public static void main(String[] args) throws Exception {
0c381f0ac967 7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff changeset
    52
        File src = new File("C.java");
0c381f0ac967 7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff changeset
    53
        Writer w = new FileWriter(src);
0c381f0ac967 7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff changeset
    54
        try {
0c381f0ac967 7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff changeset
    55
            w.write("import static p.Generated.m;\nclass C { {m(); } }\n");
0c381f0ac967 7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff changeset
    56
            w.flush();
0c381f0ac967 7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff changeset
    57
        } finally {
0c381f0ac967 7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff changeset
    58
            w.close();
0c381f0ac967 7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff changeset
    59
        }
0c381f0ac967 7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff changeset
    60
        JavaCompiler jc = ToolProvider.getSystemJavaCompiler();
0c381f0ac967 7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff changeset
    61
        JavaCompiler.CompilationTask task = jc.getTask(null, null, null, null, null,
0c381f0ac967 7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff changeset
    62
                                                       jc.getStandardFileManager(null, null, null).getJavaFileObjects(src));
0c381f0ac967 7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff changeset
    63
        task.setProcessors(Collections.singleton(new Proc()));
0c381f0ac967 7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff changeset
    64
        if (!task.call()) {
0c381f0ac967 7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff changeset
    65
            throw new Error("Test failed");
0c381f0ac967 7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff changeset
    66
        }
0c381f0ac967 7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff changeset
    67
    }
0c381f0ac967 7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff changeset
    68
0c381f0ac967 7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff changeset
    69
    private static class Proc extends JavacTestingAbstractProcessor {
0c381f0ac967 7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff changeset
    70
        int written;
0c381f0ac967 7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff changeset
    71
        @Override public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
0c381f0ac967 7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff changeset
    72
            if (roundEnv.processingOver() || written++ > 0) {
0c381f0ac967 7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff changeset
    73
                return false;
0c381f0ac967 7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff changeset
    74
            }
0c381f0ac967 7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff changeset
    75
            messager.printMessage(Diagnostic.Kind.NOTE, "writing Generated.java");
0c381f0ac967 7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff changeset
    76
            try {
0c381f0ac967 7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff changeset
    77
                Writer w = processingEnv.getFiler().createSourceFile("p.Generated").openWriter();
0c381f0ac967 7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff changeset
    78
                try {
0c381f0ac967 7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff changeset
    79
                    w.write("package p; public class Generated { public static void m() { } }");
0c381f0ac967 7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff changeset
    80
                } finally {
0c381f0ac967 7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff changeset
    81
                    w.close();
0c381f0ac967 7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff changeset
    82
                }
0c381f0ac967 7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff changeset
    83
            } catch (IOException x) {
0c381f0ac967 7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff changeset
    84
                messager.printMessage(Diagnostic.Kind.ERROR, x.toString());
0c381f0ac967 7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff changeset
    85
            }
0c381f0ac967 7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff changeset
    86
            return true;
0c381f0ac967 7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff changeset
    87
        }
0c381f0ac967 7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff changeset
    88
    }
0c381f0ac967 7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff changeset
    89
}