changeset 1153:4844a9fd3a62

6449184: Provide JavacProcessingEnvironment.getWriter Reviewed-by: jjg
author darcy
date Wed, 22 Jun 2011 17:07:02 -0700
parents 3b1fd4ac2e71
children 18002d039806 d59414955614
files src/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java test/tools/javac/util/T6597678.java
diffstat 2 files changed, 22 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java	Mon Jun 13 12:17:14 2011 -0700
+++ b/src/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java	Wed Jun 22 17:07:02 2011 -0700
@@ -1516,6 +1516,14 @@
         return context;
     }
 
+    /**
+     * Internal use method to return the writer being used by the
+     * processing environment.
+     */
+    public PrintWriter getWriter() {
+        return context.get(Log.outKey);
+    }
+
     public String toString() {
         return "javac ProcessingEnvironment";
     }
--- a/test/tools/javac/util/T6597678.java	Mon Jun 13 12:17:14 2011 -0700
+++ b/test/tools/javac/util/T6597678.java	Wed Jun 22 17:07:02 2011 -0700
@@ -23,7 +23,7 @@
 
 /**
  * @test
- * @bug 6597678
+ * @bug 6597678 6449184
  * @summary Ensure Messages propogated between rounds
  * @library ../lib
  * @build JavacTestingAbstractProcessor T6597678
@@ -42,26 +42,28 @@
 import com.sun.tools.javac.util.Context;
 import com.sun.tools.javac.util.JavacMessages;
 
+@SupportedOptions("WriterString")
 public class T6597678 extends JavacTestingAbstractProcessor {
     public static void main(String... args) throws Exception {
         new T6597678().run();
     }
 
-
     void run() throws Exception {
         String myName = T6597678.class.getSimpleName();
         File testSrc = new File(System.getProperty("test.src"));
         File file = new File(testSrc, myName + ".java");
 
-        compile(
+        StringWriter sw = new StringWriter();
+        PrintWriter pw = new PrintWriter(sw);
+
+        compile(sw, pw,
             "-proc:only",
             "-processor", myName,
+            "-AWriterString=" + pw.toString(),
             file.getPath());
     }
 
-    void compile(String... args) throws Exception {
-        StringWriter sw = new StringWriter();
-        PrintWriter pw = new PrintWriter(sw);
+    void compile(StringWriter sw, PrintWriter pw, String... args) throws Exception {
         int rc = com.sun.tools.javac.Main.compile(args, pw);
         pw.close();
         String out = sw.toString();
@@ -76,6 +78,7 @@
     @Override
     public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
         Context context = ((JavacProcessingEnvironment) processingEnv).getContext();
+        PrintWriter out = ((JavacProcessingEnvironment) processingEnv).getWriter();
         Locale locale = context.get(Locale.class);
         JavacMessages messages = context.get(JavacMessages.messagesKey);
 
@@ -83,9 +86,13 @@
         if (round == 1) {
             initialLocale = locale;
             initialMessages = messages;
+            initialWriter = out;
+
+            checkEqual("writerString", out.toString().intern(), options.get("WriterString").intern());
         } else {
             checkEqual("locale", locale, initialLocale);
             checkEqual("messages", messages, initialMessages);
+            checkEqual("writer", out, initialWriter);
         }
 
         return true;
@@ -102,4 +109,5 @@
     int round = 0;
     Locale initialLocale;
     JavacMessages initialMessages;
+    PrintWriter initialWriter;
 }