提交 538ebcac 编写于 作者: D darcy

6449184: Provide JavacProcessingEnvironment.getWriter

Reviewed-by: jjg
上级 091cc452
...@@ -1516,6 +1516,14 @@ public class JavacProcessingEnvironment implements ProcessingEnvironment, Closea ...@@ -1516,6 +1516,14 @@ public class JavacProcessingEnvironment implements ProcessingEnvironment, Closea
return context; 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() { public String toString() {
return "javac ProcessingEnvironment"; return "javac ProcessingEnvironment";
} }
......
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
/** /**
* @test * @test
* @bug 6597678 * @bug 6597678 6449184
* @summary Ensure Messages propogated between rounds * @summary Ensure Messages propogated between rounds
* @library ../lib * @library ../lib
* @build JavacTestingAbstractProcessor T6597678 * @build JavacTestingAbstractProcessor T6597678
...@@ -42,26 +42,28 @@ import com.sun.tools.javac.processing.JavacProcessingEnvironment; ...@@ -42,26 +42,28 @@ import com.sun.tools.javac.processing.JavacProcessingEnvironment;
import com.sun.tools.javac.util.Context; import com.sun.tools.javac.util.Context;
import com.sun.tools.javac.util.JavacMessages; import com.sun.tools.javac.util.JavacMessages;
@SupportedOptions("WriterString")
public class T6597678 extends JavacTestingAbstractProcessor { public class T6597678 extends JavacTestingAbstractProcessor {
public static void main(String... args) throws Exception { public static void main(String... args) throws Exception {
new T6597678().run(); new T6597678().run();
} }
void run() throws Exception { void run() throws Exception {
String myName = T6597678.class.getSimpleName(); String myName = T6597678.class.getSimpleName();
File testSrc = new File(System.getProperty("test.src")); File testSrc = new File(System.getProperty("test.src"));
File file = new File(testSrc, myName + ".java"); File file = new File(testSrc, myName + ".java");
compile( StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
compile(sw, pw,
"-proc:only", "-proc:only",
"-processor", myName, "-processor", myName,
"-AWriterString=" + pw.toString(),
file.getPath()); file.getPath());
} }
void compile(String... args) throws Exception { void compile(StringWriter sw, PrintWriter pw, String... args) throws Exception {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
int rc = com.sun.tools.javac.Main.compile(args, pw); int rc = com.sun.tools.javac.Main.compile(args, pw);
pw.close(); pw.close();
String out = sw.toString(); String out = sw.toString();
...@@ -76,6 +78,7 @@ public class T6597678 extends JavacTestingAbstractProcessor { ...@@ -76,6 +78,7 @@ public class T6597678 extends JavacTestingAbstractProcessor {
@Override @Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
Context context = ((JavacProcessingEnvironment) processingEnv).getContext(); Context context = ((JavacProcessingEnvironment) processingEnv).getContext();
PrintWriter out = ((JavacProcessingEnvironment) processingEnv).getWriter();
Locale locale = context.get(Locale.class); Locale locale = context.get(Locale.class);
JavacMessages messages = context.get(JavacMessages.messagesKey); JavacMessages messages = context.get(JavacMessages.messagesKey);
...@@ -83,9 +86,13 @@ public class T6597678 extends JavacTestingAbstractProcessor { ...@@ -83,9 +86,13 @@ public class T6597678 extends JavacTestingAbstractProcessor {
if (round == 1) { if (round == 1) {
initialLocale = locale; initialLocale = locale;
initialMessages = messages; initialMessages = messages;
initialWriter = out;
checkEqual("writerString", out.toString().intern(), options.get("WriterString").intern());
} else { } else {
checkEqual("locale", locale, initialLocale); checkEqual("locale", locale, initialLocale);
checkEqual("messages", messages, initialMessages); checkEqual("messages", messages, initialMessages);
checkEqual("writer", out, initialWriter);
} }
return true; return true;
...@@ -102,4 +109,5 @@ public class T6597678 extends JavacTestingAbstractProcessor { ...@@ -102,4 +109,5 @@ public class T6597678 extends JavacTestingAbstractProcessor {
int round = 0; int round = 0;
Locale initialLocale; Locale initialLocale;
JavacMessages initialMessages; JavacMessages initialMessages;
PrintWriter initialWriter;
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册