author | robm |
Tue, 13 Sep 2016 14:47:29 +0100 | |
changeset 40938 | 5b0977acc842 |
parent 30730 | d3ce7619db2c |
permissions | -rw-r--r-- |
12917
0c381f0ac967
7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff
changeset
|
1 |
/* |
30730
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
27319
diff
changeset
|
2 |
* Copyright (c) 2010, 2015, Oracle and/or its affiliates. All rights reserved. |
12917
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 |
30730
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
27319
diff
changeset
|
29 |
* @modules java.compiler |
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
27319
diff
changeset
|
30 |
* jdk.compiler |
12917
0c381f0ac967
7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff
changeset
|
31 |
* @build JavacTestingAbstractProcessor |
0c381f0ac967
7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff
changeset
|
32 |
* @run main T7159016 |
0c381f0ac967
7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff
changeset
|
33 |
* @author Jessie Glick |
0c381f0ac967
7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff
changeset
|
34 |
*/ |
0c381f0ac967
7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff
changeset
|
35 |
|
0c381f0ac967
7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff
changeset
|
36 |
import java.io.File; |
0c381f0ac967
7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff
changeset
|
37 |
import java.io.FileWriter; |
0c381f0ac967
7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff
changeset
|
38 |
import java.io.IOException; |
0c381f0ac967
7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff
changeset
|
39 |
import java.io.Writer; |
0c381f0ac967
7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff
changeset
|
40 |
import java.util.Collections; |
0c381f0ac967
7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff
changeset
|
41 |
import java.util.Set; |
0c381f0ac967
7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff
changeset
|
42 |
import javax.annotation.processing.AbstractProcessor; |
0c381f0ac967
7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff
changeset
|
43 |
import javax.annotation.processing.RoundEnvironment; |
0c381f0ac967
7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff
changeset
|
44 |
import javax.annotation.processing.SupportedAnnotationTypes; |
0c381f0ac967
7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff
changeset
|
45 |
import javax.annotation.processing.SupportedSourceVersion; |
0c381f0ac967
7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff
changeset
|
46 |
import javax.lang.model.SourceVersion; |
0c381f0ac967
7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff
changeset
|
47 |
import javax.lang.model.element.TypeElement; |
0c381f0ac967
7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff
changeset
|
48 |
import javax.tools.Diagnostic; |
0c381f0ac967
7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff
changeset
|
49 |
import javax.tools.JavaCompiler; |
27319
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
12917
diff
changeset
|
50 |
import javax.tools.StandardJavaFileManager; |
12917
0c381f0ac967
7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff
changeset
|
51 |
import javax.tools.ToolProvider; |
0c381f0ac967
7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff
changeset
|
52 |
|
0c381f0ac967
7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff
changeset
|
53 |
public class T7159016 { |
0c381f0ac967
7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff
changeset
|
54 |
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
|
55 |
File src = new File("C.java"); |
0c381f0ac967
7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff
changeset
|
56 |
Writer w = new FileWriter(src); |
0c381f0ac967
7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff
changeset
|
57 |
try { |
0c381f0ac967
7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff
changeset
|
58 |
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
|
59 |
w.flush(); |
0c381f0ac967
7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff
changeset
|
60 |
} finally { |
0c381f0ac967
7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff
changeset
|
61 |
w.close(); |
0c381f0ac967
7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff
changeset
|
62 |
} |
0c381f0ac967
7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff
changeset
|
63 |
JavaCompiler jc = ToolProvider.getSystemJavaCompiler(); |
27319
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
12917
diff
changeset
|
64 |
try (StandardJavaFileManager fm = jc.getStandardFileManager(null, null, null)) { |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
12917
diff
changeset
|
65 |
JavaCompiler.CompilationTask task = jc.getTask(null, fm, null, null, null, |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
12917
diff
changeset
|
66 |
fm.getJavaFileObjects(src)); |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
12917
diff
changeset
|
67 |
task.setProcessors(Collections.singleton(new Proc())); |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
12917
diff
changeset
|
68 |
if (!task.call()) { |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
12917
diff
changeset
|
69 |
throw new Error("Test failed"); |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
12917
diff
changeset
|
70 |
} |
12917
0c381f0ac967
7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff
changeset
|
71 |
} |
0c381f0ac967
7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff
changeset
|
72 |
} |
0c381f0ac967
7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff
changeset
|
73 |
|
0c381f0ac967
7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff
changeset
|
74 |
private static class Proc extends JavacTestingAbstractProcessor { |
0c381f0ac967
7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff
changeset
|
75 |
int written; |
0c381f0ac967
7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff
changeset
|
76 |
@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
|
77 |
if (roundEnv.processingOver() || written++ > 0) { |
0c381f0ac967
7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff
changeset
|
78 |
return false; |
0c381f0ac967
7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff
changeset
|
79 |
} |
0c381f0ac967
7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff
changeset
|
80 |
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
|
81 |
try { |
0c381f0ac967
7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff
changeset
|
82 |
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
|
83 |
try { |
0c381f0ac967
7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff
changeset
|
84 |
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
|
85 |
} finally { |
0c381f0ac967
7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff
changeset
|
86 |
w.close(); |
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 |
} catch (IOException x) { |
0c381f0ac967
7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff
changeset
|
89 |
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
|
90 |
} |
0c381f0ac967
7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff
changeset
|
91 |
return true; |
0c381f0ac967
7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff
changeset
|
92 |
} |
0c381f0ac967
7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff
changeset
|
93 |
} |
0c381f0ac967
7159016: Static import of member in processor-generated class fails in JDK 7
jjh
parents:
diff
changeset
|
94 |
} |