author | asaha |
Tue, 14 Jan 2014 08:08:32 -0800 | |
changeset 22449 | 1fd6d4bec7dd |
parent 14963 | 974d4423c999 |
child 30730 | d3ce7619db2c |
permissions | -rw-r--r-- |
6924
ef7a9281ad2f
6988836: A new JavacElements is created for each round of annotation processing
jjg
parents:
diff
changeset
|
1 |
/* |
8846
39157538c506
6987384: -XprintProcessorRoundsInfo message printed with different timing than previous
jjg
parents:
6924
diff
changeset
|
2 |
* Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved. |
6924
ef7a9281ad2f
6988836: A new JavacElements is created for each round of annotation processing
jjg
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
ef7a9281ad2f
6988836: A new JavacElements is created for each round of annotation processing
jjg
parents:
diff
changeset
|
4 |
* |
ef7a9281ad2f
6988836: A new JavacElements is created for each round of annotation processing
jjg
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
ef7a9281ad2f
6988836: A new JavacElements is created for each round of annotation processing
jjg
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
ef7a9281ad2f
6988836: A new JavacElements is created for each round of annotation processing
jjg
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
ef7a9281ad2f
6988836: A new JavacElements is created for each round of annotation processing
jjg
parents:
diff
changeset
|
8 |
* |
ef7a9281ad2f
6988836: A new JavacElements is created for each round of annotation processing
jjg
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
ef7a9281ad2f
6988836: A new JavacElements is created for each round of annotation processing
jjg
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
ef7a9281ad2f
6988836: A new JavacElements is created for each round of annotation processing
jjg
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
ef7a9281ad2f
6988836: A new JavacElements is created for each round of annotation processing
jjg
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
ef7a9281ad2f
6988836: A new JavacElements is created for each round of annotation processing
jjg
parents:
diff
changeset
|
13 |
* accompanied this code). |
ef7a9281ad2f
6988836: A new JavacElements is created for each round of annotation processing
jjg
parents:
diff
changeset
|
14 |
* |
ef7a9281ad2f
6988836: A new JavacElements is created for each round of annotation processing
jjg
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
ef7a9281ad2f
6988836: A new JavacElements is created for each round of annotation processing
jjg
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
ef7a9281ad2f
6988836: A new JavacElements is created for each round of annotation processing
jjg
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
ef7a9281ad2f
6988836: A new JavacElements is created for each round of annotation processing
jjg
parents:
diff
changeset
|
18 |
* |
ef7a9281ad2f
6988836: A new JavacElements is created for each round of annotation processing
jjg
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
ef7a9281ad2f
6988836: A new JavacElements is created for each round of annotation processing
jjg
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
ef7a9281ad2f
6988836: A new JavacElements is created for each round of annotation processing
jjg
parents:
diff
changeset
|
21 |
* questions. |
ef7a9281ad2f
6988836: A new JavacElements is created for each round of annotation processing
jjg
parents:
diff
changeset
|
22 |
*/ |
ef7a9281ad2f
6988836: A new JavacElements is created for each round of annotation processing
jjg
parents:
diff
changeset
|
23 |
|
ef7a9281ad2f
6988836: A new JavacElements is created for each round of annotation processing
jjg
parents:
diff
changeset
|
24 |
/* |
ef7a9281ad2f
6988836: A new JavacElements is created for each round of annotation processing
jjg
parents:
diff
changeset
|
25 |
* @test |
ef7a9281ad2f
6988836: A new JavacElements is created for each round of annotation processing
jjg
parents:
diff
changeset
|
26 |
* @bug 6988836 |
ef7a9281ad2f
6988836: A new JavacElements is created for each round of annotation processing
jjg
parents:
diff
changeset
|
27 |
* @summary A new JavacElements is created for each round of annotation processing |
14963
974d4423c999
8005282: Use @library tag with non-relative path for javac tests
darcy
parents:
8846
diff
changeset
|
28 |
* @library /tools/javac/lib |
6924
ef7a9281ad2f
6988836: A new JavacElements is created for each round of annotation processing
jjg
parents:
diff
changeset
|
29 |
* @build JavacTestingAbstractProcessor TestContext |
ef7a9281ad2f
6988836: A new JavacElements is created for each round of annotation processing
jjg
parents:
diff
changeset
|
30 |
* @compile/process -processor TestContext -XprintRounds TestContext |
ef7a9281ad2f
6988836: A new JavacElements is created for each round of annotation processing
jjg
parents:
diff
changeset
|
31 |
*/ |
ef7a9281ad2f
6988836: A new JavacElements is created for each round of annotation processing
jjg
parents:
diff
changeset
|
32 |
|
ef7a9281ad2f
6988836: A new JavacElements is created for each round of annotation processing
jjg
parents:
diff
changeset
|
33 |
import java.io.*; |
ef7a9281ad2f
6988836: A new JavacElements is created for each round of annotation processing
jjg
parents:
diff
changeset
|
34 |
import java.util.*; |
ef7a9281ad2f
6988836: A new JavacElements is created for each round of annotation processing
jjg
parents:
diff
changeset
|
35 |
import javax.annotation.processing.*; |
ef7a9281ad2f
6988836: A new JavacElements is created for each round of annotation processing
jjg
parents:
diff
changeset
|
36 |
import javax.lang.model.element.*; |
ef7a9281ad2f
6988836: A new JavacElements is created for each round of annotation processing
jjg
parents:
diff
changeset
|
37 |
import static javax.tools.Diagnostic.Kind.*; |
ef7a9281ad2f
6988836: A new JavacElements is created for each round of annotation processing
jjg
parents:
diff
changeset
|
38 |
|
ef7a9281ad2f
6988836: A new JavacElements is created for each round of annotation processing
jjg
parents:
diff
changeset
|
39 |
import com.sun.source.util.Trees; |
ef7a9281ad2f
6988836: A new JavacElements is created for each round of annotation processing
jjg
parents:
diff
changeset
|
40 |
import com.sun.tools.javac.api.JavacTrees; |
ef7a9281ad2f
6988836: A new JavacElements is created for each round of annotation processing
jjg
parents:
diff
changeset
|
41 |
import com.sun.tools.javac.model.JavacElements; |
ef7a9281ad2f
6988836: A new JavacElements is created for each round of annotation processing
jjg
parents:
diff
changeset
|
42 |
import com.sun.tools.javac.model.JavacTypes; |
ef7a9281ad2f
6988836: A new JavacElements is created for each round of annotation processing
jjg
parents:
diff
changeset
|
43 |
import com.sun.tools.javac.processing.JavacProcessingEnvironment; |
ef7a9281ad2f
6988836: A new JavacElements is created for each round of annotation processing
jjg
parents:
diff
changeset
|
44 |
import com.sun.tools.javac.util.Context; |
ef7a9281ad2f
6988836: A new JavacElements is created for each round of annotation processing
jjg
parents:
diff
changeset
|
45 |
|
ef7a9281ad2f
6988836: A new JavacElements is created for each round of annotation processing
jjg
parents:
diff
changeset
|
46 |
public class TestContext extends JavacTestingAbstractProcessor { |
ef7a9281ad2f
6988836: A new JavacElements is created for each round of annotation processing
jjg
parents:
diff
changeset
|
47 |
|
ef7a9281ad2f
6988836: A new JavacElements is created for each round of annotation processing
jjg
parents:
diff
changeset
|
48 |
Trees treeUtils; |
ef7a9281ad2f
6988836: A new JavacElements is created for each round of annotation processing
jjg
parents:
diff
changeset
|
49 |
int round = 0; |
ef7a9281ad2f
6988836: A new JavacElements is created for each round of annotation processing
jjg
parents:
diff
changeset
|
50 |
|
ef7a9281ad2f
6988836: A new JavacElements is created for each round of annotation processing
jjg
parents:
diff
changeset
|
51 |
@Override |
ef7a9281ad2f
6988836: A new JavacElements is created for each round of annotation processing
jjg
parents:
diff
changeset
|
52 |
public void init(ProcessingEnvironment pEnv) { |
ef7a9281ad2f
6988836: A new JavacElements is created for each round of annotation processing
jjg
parents:
diff
changeset
|
53 |
super.init(pEnv); |
ef7a9281ad2f
6988836: A new JavacElements is created for each round of annotation processing
jjg
parents:
diff
changeset
|
54 |
treeUtils = Trees.instance(processingEnv); |
ef7a9281ad2f
6988836: A new JavacElements is created for each round of annotation processing
jjg
parents:
diff
changeset
|
55 |
} |
ef7a9281ad2f
6988836: A new JavacElements is created for each round of annotation processing
jjg
parents:
diff
changeset
|
56 |
|
ef7a9281ad2f
6988836: A new JavacElements is created for each round of annotation processing
jjg
parents:
diff
changeset
|
57 |
@Override |
ef7a9281ad2f
6988836: A new JavacElements is created for each round of annotation processing
jjg
parents:
diff
changeset
|
58 |
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { |
ef7a9281ad2f
6988836: A new JavacElements is created for each round of annotation processing
jjg
parents:
diff
changeset
|
59 |
round++; |
ef7a9281ad2f
6988836: A new JavacElements is created for each round of annotation processing
jjg
parents:
diff
changeset
|
60 |
|
ef7a9281ad2f
6988836: A new JavacElements is created for each round of annotation processing
jjg
parents:
diff
changeset
|
61 |
JavacProcessingEnvironment jpe = (JavacProcessingEnvironment) processingEnv; |
ef7a9281ad2f
6988836: A new JavacElements is created for each round of annotation processing
jjg
parents:
diff
changeset
|
62 |
Context c = jpe.getContext(); |
ef7a9281ad2f
6988836: A new JavacElements is created for each round of annotation processing
jjg
parents:
diff
changeset
|
63 |
check(c.get(JavacElements.class), eltUtils); |
ef7a9281ad2f
6988836: A new JavacElements is created for each round of annotation processing
jjg
parents:
diff
changeset
|
64 |
check(c.get(JavacTypes.class), typeUtils); |
ef7a9281ad2f
6988836: A new JavacElements is created for each round of annotation processing
jjg
parents:
diff
changeset
|
65 |
check(c.get(JavacTrees.class), treeUtils); |
ef7a9281ad2f
6988836: A new JavacElements is created for each round of annotation processing
jjg
parents:
diff
changeset
|
66 |
|
ef7a9281ad2f
6988836: A new JavacElements is created for each round of annotation processing
jjg
parents:
diff
changeset
|
67 |
final int MAXROUNDS = 3; |
ef7a9281ad2f
6988836: A new JavacElements is created for each round of annotation processing
jjg
parents:
diff
changeset
|
68 |
if (round < MAXROUNDS) |
ef7a9281ad2f
6988836: A new JavacElements is created for each round of annotation processing
jjg
parents:
diff
changeset
|
69 |
generateSource("Gen" + round); |
ef7a9281ad2f
6988836: A new JavacElements is created for each round of annotation processing
jjg
parents:
diff
changeset
|
70 |
|
ef7a9281ad2f
6988836: A new JavacElements is created for each round of annotation processing
jjg
parents:
diff
changeset
|
71 |
return true; |
ef7a9281ad2f
6988836: A new JavacElements is created for each round of annotation processing
jjg
parents:
diff
changeset
|
72 |
} |
ef7a9281ad2f
6988836: A new JavacElements is created for each round of annotation processing
jjg
parents:
diff
changeset
|
73 |
|
ef7a9281ad2f
6988836: A new JavacElements is created for each round of annotation processing
jjg
parents:
diff
changeset
|
74 |
<T> void check(T actual, T expected) { |
ef7a9281ad2f
6988836: A new JavacElements is created for each round of annotation processing
jjg
parents:
diff
changeset
|
75 |
// messager.printMessage(NOTE, "expect: " + expected); |
ef7a9281ad2f
6988836: A new JavacElements is created for each round of annotation processing
jjg
parents:
diff
changeset
|
76 |
// messager.printMessage(NOTE, "actual: " + actual); |
ef7a9281ad2f
6988836: A new JavacElements is created for each round of annotation processing
jjg
parents:
diff
changeset
|
77 |
|
ef7a9281ad2f
6988836: A new JavacElements is created for each round of annotation processing
jjg
parents:
diff
changeset
|
78 |
if (actual != expected) { |
ef7a9281ad2f
6988836: A new JavacElements is created for each round of annotation processing
jjg
parents:
diff
changeset
|
79 |
messager.printMessage(ERROR, |
ef7a9281ad2f
6988836: A new JavacElements is created for each round of annotation processing
jjg
parents:
diff
changeset
|
80 |
"round " + round + " unexpected value for " + expected.getClass().getName() + ": " + actual); |
ef7a9281ad2f
6988836: A new JavacElements is created for each round of annotation processing
jjg
parents:
diff
changeset
|
81 |
} |
ef7a9281ad2f
6988836: A new JavacElements is created for each round of annotation processing
jjg
parents:
diff
changeset
|
82 |
} |
ef7a9281ad2f
6988836: A new JavacElements is created for each round of annotation processing
jjg
parents:
diff
changeset
|
83 |
|
ef7a9281ad2f
6988836: A new JavacElements is created for each round of annotation processing
jjg
parents:
diff
changeset
|
84 |
void generateSource(String name) { |
ef7a9281ad2f
6988836: A new JavacElements is created for each round of annotation processing
jjg
parents:
diff
changeset
|
85 |
String text = "class " + name + " { }\n"; |
ef7a9281ad2f
6988836: A new JavacElements is created for each round of annotation processing
jjg
parents:
diff
changeset
|
86 |
|
ef7a9281ad2f
6988836: A new JavacElements is created for each round of annotation processing
jjg
parents:
diff
changeset
|
87 |
try (Writer out = filer.createSourceFile(name).openWriter()) { |
ef7a9281ad2f
6988836: A new JavacElements is created for each round of annotation processing
jjg
parents:
diff
changeset
|
88 |
out.write(text); |
ef7a9281ad2f
6988836: A new JavacElements is created for each round of annotation processing
jjg
parents:
diff
changeset
|
89 |
} catch (IOException e) { |
ef7a9281ad2f
6988836: A new JavacElements is created for each round of annotation processing
jjg
parents:
diff
changeset
|
90 |
throw new Error(e); |
ef7a9281ad2f
6988836: A new JavacElements is created for each round of annotation processing
jjg
parents:
diff
changeset
|
91 |
} |
ef7a9281ad2f
6988836: A new JavacElements is created for each round of annotation processing
jjg
parents:
diff
changeset
|
92 |
} |
ef7a9281ad2f
6988836: A new JavacElements is created for each round of annotation processing
jjg
parents:
diff
changeset
|
93 |
|
ef7a9281ad2f
6988836: A new JavacElements is created for each round of annotation processing
jjg
parents:
diff
changeset
|
94 |
} |
ef7a9281ad2f
6988836: A new JavacElements is created for each round of annotation processing
jjg
parents:
diff
changeset
|
95 |