test/tools/javac/processing/options/testPrintProcessorInfo/Test.java

changeset 932
edf03ca74991
child 1466
b52a38d4536c
equal deleted inserted replaced
931:c9432f06d9bc 932:edf03ca74991
1 /*
2 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
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 *
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.
22 */
23
24 /*
25 * @test
26 * @bug 6987384
27 * @summary -XprintProcessorRoundsInfo message printed with different timing than previous
28 * @library ../../../lib
29 * @build JavacTestingAbstractProcessor Test
30 * @compile/fail/ref=Test.out -XDrawDiagnostics -XprintProcessorInfo -Werror -proc:only -processor Test Test.java
31 */
32
33 import java.io.*;
34 import java.util.*;
35 import javax.annotation.processing.*;
36 import javax.lang.model.*;
37 import javax.lang.model.element.*;
38 import javax.lang.model.util.*;
39 import javax.tools.*;
40
41 public class Test extends JavacTestingAbstractProcessor {
42 final int MAX_ROUNDS = 3;
43 int round = 0;
44
45 @Override
46 public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
47 round++;
48 messager.printMessage(Diagnostic.Kind.NOTE, "round " + round);
49 if (round <= MAX_ROUNDS)
50 generateSource("Gen" + round);
51 if (roundEnv.processingOver())
52 messager.printMessage(Diagnostic.Kind.WARNING, "last round");
53 return true;
54 }
55
56 void generateSource(String name) {
57 String text = "class " + name + " { }\n";
58
59 // avoid try-with-resources so test can be run on older builds
60 try {
61 Writer out = filer.createSourceFile(name).openWriter();
62 try {
63 out.write(text);
64 } finally {
65 out.close();
66 }
67 } catch (IOException e) {
68 throw new Error(e);
69 }
70 }
71 }
72
73
74

mercurial