author | never |
Fri, 25 Mar 2011 18:50:10 -0700 | |
changeset 8867 | 6febcc945802 |
parent 5520 | 86e4b9a9da40 |
child 10193 | 3e1ef5e9f4fd |
permissions | -rw-r--r-- |
10 | 1 |
/* |
5520 | 2 |
* Copyright (c) 2006, 2008, Oracle and/or its affiliates. All rights reserved. |
10 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
5520 | 19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
10 | 22 |
*/ |
23 |
||
24 |
/* |
|
25 |
* @test |
|
26 |
* @bug 6358168 |
|
27 |
* @summary JavaCompiler.hasBeenUsed is not set in delegateCompiler |
|
28 |
*/ |
|
29 |
||
30 |
import java.io.*; |
|
31 |
import java.net.*; |
|
32 |
import java.util.*; |
|
33 |
import javax.annotation.processing.*; |
|
34 |
import javax.lang.model.element.*; |
|
35 |
import javax.tools.*; |
|
731
1dd22bdb9ca5
6714364: refactor javac File handling code into new javac.file package
jjg
parents:
10
diff
changeset
|
36 |
import com.sun.tools.javac.file.*; |
811
687d51cb403b
6716866: some javac regression tests fail to compile with re-orged file manager
jjg
parents:
731
diff
changeset
|
37 |
import com.sun.tools.javac.file.JavacFileManager; |
10 | 38 |
import com.sun.tools.javac.main.JavaCompiler; |
39 |
import com.sun.tools.javac.main.*; |
|
40 |
import com.sun.tools.javac.util.*; |
|
41 |
import com.sun.tools.javac.util.List; // disambiguate |
|
42 |
||
43 |
||
44 |
@SupportedAnnotationTypes("*") |
|
45 |
public class T6358168 extends AbstractProcessor { |
|
46 |
private static String testClasses = System.getProperty("test.classes"); |
|
47 |
private static String testSrc = System.getProperty("test.src"); |
|
48 |
private static String self = T6358168.class.getName(); |
|
49 |
||
50 |
public static void main(String... args) throws Throwable { |
|
51 |
||
52 |
JavacFileManager fm = new JavacFileManager(new Context(), false, null); |
|
53 |
JavaFileObject f = fm.getFileForInput(testSrc + File.separatorChar + T6358168.class.getName() + ".java"); |
|
54 |
||
55 |
try { |
|
56 |
// first, test case with no annotation processing |
|
57 |
testNoAnnotationProcessing(fm, f); |
|
58 |
||
59 |
// now, test case with annotation processing |
|
60 |
testAnnotationProcessing(fm, f); |
|
61 |
} |
|
62 |
catch (Throwable t) { |
|
63 |
AssertionError e = new AssertionError(); |
|
64 |
e.initCause(t); |
|
65 |
throw e; |
|
66 |
} |
|
67 |
} |
|
68 |
||
69 |
static void testNoAnnotationProcessing(JavacFileManager fm, JavaFileObject f) throws Throwable { |
|
70 |
Context context = new Context(); |
|
71 |
fm.setContext(context); |
|
72 |
||
73 |
Main compilerMain = new Main("javac", new PrintWriter(System.err, true)); |
|
74 |
compilerMain.setOptions(Options.instance(context)); |
|
75 |
compilerMain.filenames = new ListBuffer<File>(); |
|
76 |
compilerMain.processArgs(new String[] { "-d", "." }); |
|
77 |
||
78 |
JavaCompiler compiler = JavaCompiler.instance(context); |
|
79 |
compiler.compile(List.of(f)); |
|
80 |
try { |
|
81 |
compiler.compile(List.of(f)); |
|
82 |
throw new Error("Error: AssertionError not thrown after second call of compile"); |
|
83 |
} catch (AssertionError e) { |
|
84 |
System.err.println("Exception from compiler (expected): " + e); |
|
85 |
} |
|
86 |
} |
|
87 |
||
88 |
static void testAnnotationProcessing(JavacFileManager fm, JavaFileObject f) throws Throwable { |
|
89 |
Context context = new Context(); |
|
90 |
fm.setContext(context); |
|
91 |
||
92 |
Main compilerMain = new Main("javac", new PrintWriter(System.err, true)); |
|
93 |
compilerMain.setOptions(Options.instance(context)); |
|
94 |
compilerMain.filenames = new ListBuffer<File>(); |
|
95 |
compilerMain.processArgs(new String[] { |
|
96 |
"-XprintRounds", |
|
97 |
"-processorpath", testClasses, |
|
98 |
"-processor", self, |
|
99 |
"-d", "."}); |
|
100 |
||
101 |
JavaCompiler compiler = JavaCompiler.instance(context); |
|
102 |
compiler.initProcessAnnotations(null); |
|
103 |
JavaCompiler compiler2 = compiler.processAnnotations(compiler.enterTrees(compiler.parseFiles(List.of(f)))); |
|
104 |
try { |
|
105 |
compiler2.compile(List.of(f)); |
|
106 |
throw new Error("Error: AssertionError not thrown after second call of compile"); |
|
107 |
} catch (AssertionError e) { |
|
108 |
System.err.println("Exception from compiler (expected): " + e); |
|
109 |
} |
|
110 |
} |
|
111 |
||
112 |
public boolean process(Set<? extends TypeElement> tes, RoundEnvironment renv) { |
|
113 |
return true; |
|
114 |
} |
|
115 |
} |