test/tools/javac/util/T6597678.java

changeset 1044
4844a9fd3a62
parent 944
83260b3305ac
child 1159
4261dc8af622
equal deleted inserted replaced
1043:3b1fd4ac2e71 1044:4844a9fd3a62
21 * questions. 21 * questions.
22 */ 22 */
23 23
24 /** 24 /**
25 * @test 25 * @test
26 * @bug 6597678 26 * @bug 6597678 6449184
27 * @summary Ensure Messages propogated between rounds 27 * @summary Ensure Messages propogated between rounds
28 * @library ../lib 28 * @library ../lib
29 * @build JavacTestingAbstractProcessor T6597678 29 * @build JavacTestingAbstractProcessor T6597678
30 * @run main T6597678 30 * @run main T6597678
31 */ 31 */
40 40
41 import com.sun.tools.javac.processing.JavacProcessingEnvironment; 41 import com.sun.tools.javac.processing.JavacProcessingEnvironment;
42 import com.sun.tools.javac.util.Context; 42 import com.sun.tools.javac.util.Context;
43 import com.sun.tools.javac.util.JavacMessages; 43 import com.sun.tools.javac.util.JavacMessages;
44 44
45 @SupportedOptions("WriterString")
45 public class T6597678 extends JavacTestingAbstractProcessor { 46 public class T6597678 extends JavacTestingAbstractProcessor {
46 public static void main(String... args) throws Exception { 47 public static void main(String... args) throws Exception {
47 new T6597678().run(); 48 new T6597678().run();
48 } 49 }
49
50 50
51 void run() throws Exception { 51 void run() throws Exception {
52 String myName = T6597678.class.getSimpleName(); 52 String myName = T6597678.class.getSimpleName();
53 File testSrc = new File(System.getProperty("test.src")); 53 File testSrc = new File(System.getProperty("test.src"));
54 File file = new File(testSrc, myName + ".java"); 54 File file = new File(testSrc, myName + ".java");
55 55
56 compile( 56 StringWriter sw = new StringWriter();
57 PrintWriter pw = new PrintWriter(sw);
58
59 compile(sw, pw,
57 "-proc:only", 60 "-proc:only",
58 "-processor", myName, 61 "-processor", myName,
62 "-AWriterString=" + pw.toString(),
59 file.getPath()); 63 file.getPath());
60 } 64 }
61 65
62 void compile(String... args) throws Exception { 66 void compile(StringWriter sw, PrintWriter pw, String... args) throws Exception {
63 StringWriter sw = new StringWriter();
64 PrintWriter pw = new PrintWriter(sw);
65 int rc = com.sun.tools.javac.Main.compile(args, pw); 67 int rc = com.sun.tools.javac.Main.compile(args, pw);
66 pw.close(); 68 pw.close();
67 String out = sw.toString(); 69 String out = sw.toString();
68 if (!out.isEmpty()) 70 if (!out.isEmpty())
69 System.err.println(out); 71 System.err.println(out);
74 //--------------- 76 //---------------
75 77
76 @Override 78 @Override
77 public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { 79 public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
78 Context context = ((JavacProcessingEnvironment) processingEnv).getContext(); 80 Context context = ((JavacProcessingEnvironment) processingEnv).getContext();
81 PrintWriter out = ((JavacProcessingEnvironment) processingEnv).getWriter();
79 Locale locale = context.get(Locale.class); 82 Locale locale = context.get(Locale.class);
80 JavacMessages messages = context.get(JavacMessages.messagesKey); 83 JavacMessages messages = context.get(JavacMessages.messagesKey);
81 84
82 round++; 85 round++;
83 if (round == 1) { 86 if (round == 1) {
84 initialLocale = locale; 87 initialLocale = locale;
85 initialMessages = messages; 88 initialMessages = messages;
89 initialWriter = out;
90
91 checkEqual("writerString", out.toString().intern(), options.get("WriterString").intern());
86 } else { 92 } else {
87 checkEqual("locale", locale, initialLocale); 93 checkEqual("locale", locale, initialLocale);
88 checkEqual("messages", messages, initialMessages); 94 checkEqual("messages", messages, initialMessages);
95 checkEqual("writer", out, initialWriter);
89 } 96 }
90 97
91 return true; 98 return true;
92 } 99 }
93 100
100 } 107 }
101 108
102 int round = 0; 109 int round = 0;
103 Locale initialLocale; 110 Locale initialLocale;
104 JavacMessages initialMessages; 111 JavacMessages initialMessages;
112 PrintWriter initialWriter;
105 } 113 }

mercurial