author | sogoel |
Thu, 05 Jun 2014 10:57:10 -0700 | |
changeset 24797 | 850ebd4d80a7 |
parent 23810 | b92eb80925f0 |
child 26100 | bb7dd001d190 |
permissions | -rw-r--r-- |
23810
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
1 |
/* |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
2 |
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
4 |
* |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
8 |
* |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
13 |
* accompanied this code). |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
14 |
* |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
18 |
* |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
21 |
* questions. |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
22 |
*/ |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
23 |
|
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
24 |
/* |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
25 |
* @test |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
26 |
* @bug 8038455 |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
27 |
* @summary Ensure that formatting diagnostics with an already closed JavaCompiler won't crash |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
28 |
* the compiler. |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
29 |
* @library /tools/javac/lib |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
30 |
* @build CompleteOnClosed ToolBox JavacTestingAbstractProcessor |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
31 |
* @run main CompleteOnClosed |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
32 |
*/ |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
33 |
|
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
34 |
import java.util.*; |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
35 |
import javax.annotation.processing.*; |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
36 |
import javax.lang.model.element.TypeElement; |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
37 |
import javax.tools.Diagnostic; |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
38 |
import javax.tools.DiagnosticCollector; |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
39 |
import javax.tools.JavaCompiler; |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
40 |
import javax.tools.JavaCompiler.CompilationTask; |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
41 |
import javax.tools.JavaFileObject; |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
42 |
import javax.tools.ToolProvider; |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
43 |
|
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
44 |
public class CompleteOnClosed extends JavacTestingAbstractProcessor { |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
45 |
public static void main(String... args) { |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
46 |
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
47 |
DiagnosticCollector<JavaFileObject> collector = new DiagnosticCollector<>(); |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
48 |
String source = "class Test extends CompleteOnClosedOther {" + |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
49 |
" class Inner extends Undefined { }" + |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
50 |
"}"; |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
51 |
Iterable<JavaFileObject> files = Arrays.<JavaFileObject>asList(new ToolBox.JavaSource(source)); |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
52 |
Iterable<String> options = Arrays.asList("-processor", "CompleteOnClosed"); |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
53 |
CompilationTask task = compiler.getTask(null, null, collector, options, null, files); |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
54 |
task.call(); |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
55 |
for (Diagnostic<? extends JavaFileObject> d : collector.getDiagnostics()) { |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
56 |
System.out.println(d.toString()); |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
57 |
} |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
58 |
} |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
59 |
|
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
60 |
@Override |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
61 |
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
62 |
return false; |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
63 |
} |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
diff
changeset
|
64 |
} |