author | jjg |
Tue, 24 Aug 2010 11:31:00 -0700 | |
changeset 6572 | 4ca2051ff71a |
child 30730 | d3ce7619db2c |
permissions | -rw-r--r-- |
6572
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
diff
changeset
|
1 |
/* |
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
diff
changeset
|
2 |
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. |
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
diff
changeset
|
4 |
* |
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
diff
changeset
|
8 |
* |
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
diff
changeset
|
13 |
* accompanied this code). |
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
diff
changeset
|
14 |
* |
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
diff
changeset
|
18 |
* |
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
diff
changeset
|
21 |
* questions. |
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
diff
changeset
|
22 |
*/ |
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
diff
changeset
|
23 |
|
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
diff
changeset
|
24 |
/* |
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
diff
changeset
|
25 |
* @test |
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
diff
changeset
|
26 |
* @bug 6935638 |
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
diff
changeset
|
27 |
* @summary -implicit:none prevents compilation with annotation processing |
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
diff
changeset
|
28 |
*/ |
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
diff
changeset
|
29 |
|
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
diff
changeset
|
30 |
import java.io.*; |
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
diff
changeset
|
31 |
import java.util.*; |
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
diff
changeset
|
32 |
import javax.annotation.processing.*; |
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
diff
changeset
|
33 |
import javax.lang.model.*; |
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
diff
changeset
|
34 |
import javax.lang.model.element.*; |
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
diff
changeset
|
35 |
|
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
diff
changeset
|
36 |
|
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
diff
changeset
|
37 |
@SupportedAnnotationTypes("*") |
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
diff
changeset
|
38 |
public class TestImplicitNone extends AbstractProcessor { |
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
diff
changeset
|
39 |
public static void main(String... args) throws Exception { |
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
diff
changeset
|
40 |
new TestImplicitNone().run(); |
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
diff
changeset
|
41 |
} |
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
diff
changeset
|
42 |
|
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
diff
changeset
|
43 |
void run() throws Exception { |
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
diff
changeset
|
44 |
File classesDir = new File("tmp", "classes"); |
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
diff
changeset
|
45 |
classesDir.mkdirs(); |
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
diff
changeset
|
46 |
File test_java = new File(new File("tmp", "src"), "Test.java"); |
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
diff
changeset
|
47 |
writeFile(test_java, "class Test { }"); |
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
diff
changeset
|
48 |
|
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
diff
changeset
|
49 |
// build up list of options and files to be compiled |
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
diff
changeset
|
50 |
List<String> opts = new ArrayList<String>(); |
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
diff
changeset
|
51 |
List<File> files = new ArrayList<File>(); |
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
diff
changeset
|
52 |
|
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
diff
changeset
|
53 |
opts.add("-d"); |
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
diff
changeset
|
54 |
opts.add(classesDir.getPath()); |
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
diff
changeset
|
55 |
opts.add("-processorpath"); |
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
diff
changeset
|
56 |
opts.add(System.getProperty("test.classes")); |
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
diff
changeset
|
57 |
opts.add("-implicit:none"); |
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
diff
changeset
|
58 |
opts.add("-processor"); |
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
diff
changeset
|
59 |
opts.add(TestImplicitNone.class.getName()); |
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
diff
changeset
|
60 |
files.add(test_java); |
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
diff
changeset
|
61 |
|
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
diff
changeset
|
62 |
compile(opts, files); |
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
diff
changeset
|
63 |
|
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
diff
changeset
|
64 |
File test_class = new File(classesDir, "Test.class"); |
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
diff
changeset
|
65 |
if (!test_class.exists()) |
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
diff
changeset
|
66 |
throw new Exception("Test.class not generated"); |
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
diff
changeset
|
67 |
} |
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
diff
changeset
|
68 |
|
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
diff
changeset
|
69 |
/** Compile files with options provided. */ |
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
diff
changeset
|
70 |
void compile(List<String> opts, List<File> files) throws Exception { |
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
diff
changeset
|
71 |
System.err.println("javac: " + opts + " " + files); |
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
diff
changeset
|
72 |
List<String> args = new ArrayList<String>(); |
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
diff
changeset
|
73 |
args.addAll(opts); |
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
diff
changeset
|
74 |
for (File f: files) |
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
diff
changeset
|
75 |
args.add(f.getPath()); |
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
diff
changeset
|
76 |
StringWriter sw = new StringWriter(); |
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
diff
changeset
|
77 |
PrintWriter pw = new PrintWriter(sw); |
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
diff
changeset
|
78 |
int rc = com.sun.tools.javac.Main.compile(args.toArray(new String[args.size()]), pw); |
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
diff
changeset
|
79 |
pw.flush(); |
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
diff
changeset
|
80 |
if (sw.getBuffer().length() > 0) |
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
diff
changeset
|
81 |
System.err.println(sw.toString()); |
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
diff
changeset
|
82 |
if (rc != 0) |
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
diff
changeset
|
83 |
throw new Exception("compilation failed: rc=" + rc); |
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
diff
changeset
|
84 |
} |
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
diff
changeset
|
85 |
|
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
diff
changeset
|
86 |
/** Write a file with a given body. */ |
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
diff
changeset
|
87 |
void writeFile(File f, String body) throws Exception { |
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
diff
changeset
|
88 |
if (f.getParentFile() != null) |
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
diff
changeset
|
89 |
f.getParentFile().mkdirs(); |
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
diff
changeset
|
90 |
Writer out = new FileWriter(f); |
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
diff
changeset
|
91 |
try { |
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
diff
changeset
|
92 |
out.write(body); |
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
diff
changeset
|
93 |
} finally { |
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
diff
changeset
|
94 |
out.close(); |
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
diff
changeset
|
95 |
} |
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
diff
changeset
|
96 |
} |
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
diff
changeset
|
97 |
|
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
diff
changeset
|
98 |
//----- annotation processor methods ----- |
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
diff
changeset
|
99 |
|
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
diff
changeset
|
100 |
public boolean process(Set<? extends TypeElement> annotations, |
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
diff
changeset
|
101 |
RoundEnvironment roundEnv) { |
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
diff
changeset
|
102 |
return true; |
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
diff
changeset
|
103 |
} |
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
diff
changeset
|
104 |
|
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
diff
changeset
|
105 |
@Override |
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
diff
changeset
|
106 |
public SourceVersion getSupportedSourceVersion() { |
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
diff
changeset
|
107 |
return SourceVersion.latest(); |
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
diff
changeset
|
108 |
} |
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
diff
changeset
|
109 |
} |