test/tools/javac/tree/TreePosRoundsTest.java

changeset 696
d4df3b6ee729
parent 695
3c9b64e55c5d
child 2525
2eb010b6cb22
equal deleted inserted replaced
695:3c9b64e55c5d 696:d4df3b6ee729
21 * questions. 21 * questions.
22 */ 22 */
23 23
24 /* 24 /*
25 * @test 25 * @test
26 * @bug 6985205 26 * @bug 6985205 6986246
27 * @summary access to tree positions and doc comments may be lost across annotation processing rounds 27 * @summary access to tree positions and doc comments may be lost across annotation processing rounds
28 * @build TreePosRoundsTest 28 * @build TreePosRoundsTest
29 * @compile -proc:only -processor TreePosRoundsTest TreePosRoundsTest.java 29 * @compile -proc:only -processor TreePosRoundsTest TreePosRoundsTest.java
30 * @run main TreePosRoundsTest 30 * @run main TreePosRoundsTest
31 */ 31 */
68 throw new Exception("processing failed"); 68 throw new Exception("processing failed");
69 } 69 }
70 70
71 Filer filer; 71 Filer filer;
72 Messager messager; 72 Messager messager;
73 Trees trees;
73 74
74 @Override 75 @Override
75 public SourceVersion getSupportedSourceVersion() { 76 public SourceVersion getSupportedSourceVersion() {
76 return SourceVersion.latest(); 77 return SourceVersion.latest();
77 } 78 }
79 @Override 80 @Override
80 public void init(ProcessingEnvironment pEnv) { 81 public void init(ProcessingEnvironment pEnv) {
81 super.init(pEnv); 82 super.init(pEnv);
82 filer = pEnv.getFiler(); 83 filer = pEnv.getFiler();
83 messager = pEnv.getMessager(); 84 messager = pEnv.getMessager();
85 trees = Trees.instance(pEnv);
84 } 86 }
85 87
86 int round = 0; 88 int round = 0;
87 89
88 @Override 90 @Override
90 round++; 92 round++;
91 93
92 // Scan trees for elements, verifying source tree positions 94 // Scan trees for elements, verifying source tree positions
93 for (Element e: roundEnv.getRootElements()) { 95 for (Element e: roundEnv.getRootElements()) {
94 try { 96 try {
95 Trees trees = Trees.instance(processingEnv); // cannot cache this across rounds
96 TreePath p = trees.getPath(e); 97 TreePath p = trees.getPath(e);
97 new TestTreeScanner(p.getCompilationUnit(), trees).scan(trees.getPath(e), null); 98 new TestTreeScanner(p.getCompilationUnit(), trees).scan(trees.getPath(e), null);
98 } catch (IOException ex) { 99 } catch (IOException ex) {
99 messager.printMessage(Diagnostic.Kind.ERROR, 100 messager.printMessage(Diagnostic.Kind.ERROR,
100 "Cannot get source: " + ex, e); 101 "Cannot get source: " + ex, e);

mercurial