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 |