7108669: cleanup Log methods for direct printing to streams
Reviewed-by: mcimadamore
--- a/langtools/src/share/classes/com/sun/tools/apt/main/Main.java Tue Nov 08 17:06:08 2011 -0800
+++ b/langtools/src/share/classes/com/sun/tools/apt/main/Main.java Tue Nov 08 17:06:58 2011 -0800
@@ -205,7 +205,7 @@
String s = " " + helpSynopsis();
out.print(s);
for (int j = s.length(); j < 29; j++) out.print(" ");
- Bark.printLines(out, getLocalizedString(descrKey));
+ Bark.printRawLines(out, getLocalizedString(descrKey));
}
}
@@ -227,7 +227,7 @@
String s = " " + helpSynopsis();
out.print(s);
for (int j = s.length(); j < 29; j++) out.print(" ");
- Bark.printLines(out, getLocalizedString(descrKey));
+ Bark.printRawLines(out, getLocalizedString(descrKey));
}
}
@@ -259,7 +259,7 @@
String s = " " + helpSynopsis();
out.print(s);
for (int j = s.length(); j < 29; j++) out.print(" ");
- Log.printLines(out, getLocalizedString(descrKey));
+ Log.printRawLines(out, getLocalizedString(descrKey));
}
};
@@ -421,7 +421,7 @@
},
new AptOption("-version", "opt.version") {
boolean process(String option) {
- Bark.printLines(out, ownName + " " + AptJavaCompiler.version());
+ Bark.printRawLines(out, ownName + " " + AptJavaCompiler.version());
return super.process(option);
}
},
@@ -660,11 +660,11 @@
/** Print a string that explains usage.
*/
void help() {
- Bark.printLines(out, getLocalizedString("msg.usage.header", ownName));
+ Bark.printRawLines(out, getLocalizedString("msg.usage.header", ownName));
for (int i=0; i < recognizedOptions.length; i++) {
recognizedOptions[i].help();
}
- Bark.printLines(out, getLocalizedString("msg.usage.footer"));
+ Bark.printRawLines(out, getLocalizedString("msg.usage.footer"));
out.println();
}
@@ -675,7 +675,7 @@
recognizedOptions[i].xhelp();
}
out.println();
- Bark.printLines(out, getLocalizedString("msg.usage.nonstandard.footer"));
+ Bark.printRawLines(out, getLocalizedString("msg.usage.nonstandard.footer"));
}
/** Report a usage error.
@@ -688,7 +688,7 @@
/** Report a warning.
*/
void warning(String key, Object... args) {
- Bark.printLines(out, ownName + ": "
+ Bark.printRawLines(out, ownName + ": "
+ getLocalizedString(key, args));
}
@@ -796,7 +796,7 @@
origFilenames = processArgs((args=CommandLine.parse(args)));
if (options.get("suppress-tool-api-removal-message") == null) {
- Bark.printLines(out, getLocalizedString("misc.Deprecation"));
+ Bark.printRawLines(out, getLocalizedString("misc.Deprecation"));
}
if (origFilenames == null) {
@@ -808,7 +808,7 @@
return EXIT_OK;
}
} catch (java.io.FileNotFoundException e) {
- Bark.printLines(out, ownName + ": " +
+ Bark.printRawLines(out, ownName + ": " +
getLocalizedString("err.file.not.found",
e.getMessage()));
return EXIT_SYSERR;
@@ -1183,7 +1183,7 @@
/** Print a message reporting an internal error.
*/
void bugMessage(Throwable ex) {
- Bark.printLines(out, getLocalizedString("msg.bug",
+ Bark.printRawLines(out, getLocalizedString("msg.bug",
AptJavaCompiler.version()));
ex.printStackTrace(out);
}
@@ -1191,34 +1191,34 @@
/** Print a message reporting an fatal error.
*/
void apMessage(AnnotationProcessingError ex) {
- Bark.printLines(out, getLocalizedString("misc.Problem"));
+ Bark.printRawLines(out, getLocalizedString("misc.Problem"));
ex.getCause().printStackTrace(out);
}
/** Print a message about sun.misc.Service problem.
*/
void sceMessage(sun.misc.ServiceConfigurationError ex) {
- Bark.printLines(out, getLocalizedString("misc.SunMiscService"));
+ Bark.printRawLines(out, getLocalizedString("misc.SunMiscService"));
ex.printStackTrace(out);
}
/** Print a message reporting an fatal error.
*/
void feMessage(Throwable ex) {
- Bark.printLines(out, ex.toString());
+ Bark.printRawLines(out, ex.toString());
}
/** Print a message reporting an input/output error.
*/
void ioMessage(Throwable ex) {
- Bark.printLines(out, getLocalizedString("msg.io"));
+ Bark.printRawLines(out, getLocalizedString("msg.io"));
ex.printStackTrace(out);
}
/** Print a message reporting an out-of-resources error.
*/
void resourceMessage(Throwable ex) {
- Bark.printLines(out, getLocalizedString("msg.resource"));
+ Bark.printRawLines(out, getLocalizedString("msg.resource"));
ex.printStackTrace(out);
}
--- a/langtools/src/share/classes/com/sun/tools/javac/api/JavacTool.java Tue Nov 08 17:06:08 2011 -0800
+++ b/langtools/src/share/classes/com/sun/tools/javac/api/JavacTool.java Tue Nov 08 17:06:58 2011 -0800
@@ -52,6 +52,7 @@
import com.sun.tools.javac.util.ClientCodeException;
import com.sun.tools.javac.util.Context;
import com.sun.tools.javac.util.Log;
+import com.sun.tools.javac.util.Log.PrefixKind;
import com.sun.tools.javac.util.Options;
import com.sun.tools.javac.util.Pair;
@@ -156,15 +157,28 @@
return new JavacFileManager(context, true, charset);
}
+ @Override
public JavacTask getTask(Writer out,
JavaFileManager fileManager,
DiagnosticListener<? super JavaFileObject> diagnosticListener,
Iterable<String> options,
Iterable<String> classes,
- Iterable<? extends JavaFileObject> compilationUnits)
+ Iterable<? extends JavaFileObject> compilationUnits) {
+ Context context = new Context();
+ return getTask(out, fileManager, diagnosticListener,
+ options, classes, compilationUnits,
+ context);
+ }
+
+ public JavacTask getTask(Writer out,
+ JavaFileManager fileManager,
+ DiagnosticListener<? super JavaFileObject> diagnosticListener,
+ Iterable<String> options,
+ Iterable<String> classes,
+ Iterable<? extends JavaFileObject> compilationUnits,
+ Context context)
{
try {
- Context context = new Context();
ClientCodeWrapper ccw = ClientCodeWrapper.instance(context);
final String kindMsg = "All compilation units must be of SOURCE kind";
@@ -212,9 +226,10 @@
return;
Options optionTable = Options.instance(context);
+ Log log = Log.instance(context);
JavacOption[] recognizedOptions =
- RecognizedOptions.getJavacToolOptions(new GrumpyHelper());
+ RecognizedOptions.getJavacToolOptions(new GrumpyHelper(log));
Iterator<String> flags = options.iterator();
while (flags.hasNext()) {
String flag = flags.next();
@@ -227,7 +242,7 @@
if (fileManager.handleOption(flag, flags)) {
continue;
} else {
- String msg = Main.getLocalizedString("err.invalid.flag", flag);
+ String msg = log.localize(PrefixKind.JAVAC, "err.invalid.flag", flag);
throw new IllegalArgumentException(msg);
}
}
@@ -235,7 +250,7 @@
JavacOption option = recognizedOptions[j];
if (option.hasArg()) {
if (!flags.hasNext()) {
- String msg = Main.getLocalizedString("err.req.arg", flag);
+ String msg = log.localize(PrefixKind.JAVAC, "err.req.arg", flag);
throw new IllegalArgumentException(msg);
}
String operand = flags.next();
@@ -269,7 +284,7 @@
public int isSupportedOption(String option) {
JavacOption[] recognizedOptions =
- RecognizedOptions.getJavacToolOptions(new GrumpyHelper());
+ RecognizedOptions.getJavacToolOptions(new GrumpyHelper(null));
for (JavacOption o : recognizedOptions) {
if (o.matches(option))
return o.hasArg() ? 1 : 0;
--- a/langtools/src/share/classes/com/sun/tools/javac/jvm/ClassReader.java Tue Nov 08 17:06:08 2011 -0800
+++ b/langtools/src/share/classes/com/sun/tools/javac/jvm/ClassReader.java Tue Nov 08 17:06:58 2011 -0800
@@ -2539,7 +2539,7 @@
* @param arg An argument for substitution into the output string.
*/
private void printCCF(String key, Object arg) {
- log.printNoteLines(key, arg);
+ log.printLines(key, arg);
}
--- a/langtools/src/share/classes/com/sun/tools/javac/main/JavaCompiler.java Tue Nov 08 17:06:08 2011 -0800
+++ b/langtools/src/share/classes/com/sun/tools/javac/main/JavaCompiler.java Tue Nov 08 17:06:58 2011 -0800
@@ -48,17 +48,18 @@
import com.sun.source.util.TaskEvent;
import com.sun.source.util.TaskListener;
-import com.sun.tools.javac.file.JavacFileManager;
-import com.sun.tools.javac.util.*;
import com.sun.tools.javac.code.*;
import com.sun.tools.javac.code.Lint.LintCategory;
import com.sun.tools.javac.code.Symbol.*;
+import com.sun.tools.javac.comp.*;
+import com.sun.tools.javac.file.JavacFileManager;
+import com.sun.tools.javac.jvm.*;
+import com.sun.tools.javac.parser.*;
+import com.sun.tools.javac.processing.*;
import com.sun.tools.javac.tree.*;
import com.sun.tools.javac.tree.JCTree.*;
-import com.sun.tools.javac.parser.*;
-import com.sun.tools.javac.comp.*;
-import com.sun.tools.javac.jvm.*;
-import com.sun.tools.javac.processing.*;
+import com.sun.tools.javac.util.*;
+import com.sun.tools.javac.util.Log.WriterKind;
import static javax.tools.StandardLocation.CLASS_OUTPUT;
import static com.sun.tools.javac.main.OptionName.*;
@@ -1602,7 +1603,7 @@
}
protected void printNote(String lines) {
- log.printLines(Log.WriterKind.NOTICE, lines);
+ log.printRawLines(Log.WriterKind.NOTICE, lines);
}
/** Print numbers of errors and warnings.
@@ -1614,7 +1615,7 @@
key = "count." + kind;
else
key = "count." + kind + ".plural";
- log.printErrLines(key, String.valueOf(count));
+ log.printLines(WriterKind.ERROR, key, String.valueOf(count));
log.flush(Log.WriterKind.ERROR);
}
}
--- a/langtools/src/share/classes/com/sun/tools/javac/main/JavacOption.java Tue Nov 08 17:06:08 2011 -0800
+++ b/langtools/src/share/classes/com/sun/tools/javac/main/JavacOption.java Tue Nov 08 17:06:58 2011 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006, 2008, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2006, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -25,10 +25,11 @@
package com.sun.tools.javac.main;
-import java.io.PrintWriter;
import java.util.LinkedHashMap;
import java.util.Map;
import com.sun.tools.javac.util.Log;
+import com.sun.tools.javac.util.Log.PrefixKind;
+import com.sun.tools.javac.util.Log.WriterKind;
import com.sun.tools.javac.util.Options;
/**
@@ -177,14 +178,14 @@
/** Print a line of documentation describing this option, if standard.
* @param out the stream to which to write the documentation
*/
- void help(PrintWriter out) {
- String s = " " + helpSynopsis();
- out.print(s);
- for (int j = Math.min(s.length(), 28); j < 29; j++) out.print(" ");
- Log.printLines(out, Main.getLocalizedString(descrKey));
+ void help(Log log) {
+ log.printRawLines(WriterKind.NOTICE,
+ String.format(" %-26s %s",
+ helpSynopsis(log),
+ log.localize(PrefixKind.JAVAC, descrKey)));
}
- String helpSynopsis() {
+ String helpSynopsis(Log log) {
StringBuilder sb = new StringBuilder();
sb.append(name);
if (argsNameKey == null) {
@@ -202,7 +203,7 @@
} else {
if (!hasSuffix)
sb.append(" ");
- sb.append(Main.getLocalizedString(argsNameKey));
+ sb.append(log.localize(PrefixKind.JAVAC, argsNameKey));
}
return sb.toString();
@@ -211,7 +212,7 @@
/** Print a line of documentation describing this option, if non-standard.
* @param out the stream to which to write the documentation
*/
- void xhelp(PrintWriter out) {}
+ void xhelp(Log log) {}
/** Process the option (with arg). Return true if error detected.
*/
@@ -271,9 +272,9 @@
super(name, descrKey, kind, choices);
}
@Override
- void help(PrintWriter out) {}
+ void help(Log log) {}
@Override
- void xhelp(PrintWriter out) { super.help(out); }
+ void xhelp(Log log) { super.help(log); }
@Override
public OptionKind getKind() { return OptionKind.EXTENDED; }
};
@@ -288,9 +289,9 @@
super(name, argsNameKey, null);
}
@Override
- void help(PrintWriter out) {}
+ void help(Log log) {}
@Override
- void xhelp(PrintWriter out) {}
+ void xhelp(Log log) {}
@Override
public OptionKind getKind() { return OptionKind.HIDDEN; }
};
--- a/langtools/src/share/classes/com/sun/tools/javac/main/Main.java Tue Nov 08 17:06:08 2011 -0800
+++ b/langtools/src/share/classes/com/sun/tools/javac/main/Main.java Tue Nov 08 17:06:58 2011 -0800
@@ -33,7 +33,6 @@
import java.security.MessageDigest;
import java.util.Collection;
import java.util.LinkedHashSet;
-import java.util.MissingResourceException;
import java.util.Set;
import javax.tools.JavaFileManager;
import javax.tools.JavaFileObject;
@@ -46,6 +45,8 @@
import com.sun.tools.javac.main.JavacOption.Option;
import com.sun.tools.javac.main.RecognizedOptions.OptionHelper;
import com.sun.tools.javac.util.*;
+import com.sun.tools.javac.util.Log.WriterKind;
+import com.sun.tools.javac.util.Log.PrefixKind;
import com.sun.tools.javac.processing.AnnotationProcessingError;
import static com.sun.tools.javac.main.OptionName.*;
@@ -110,11 +111,11 @@
}
public void printVersion() {
- Log.printLines(out, getLocalizedString("version", ownName, JavaCompiler.version()));
+ log.printLines(PrefixKind.JAVAC, "version", ownName, JavaCompiler.version());
}
public void printFullVersion() {
- Log.printLines(out, getLocalizedString("fullVersion", ownName, JavaCompiler.fullVersion()));
+ log.printLines(PrefixKind.JAVAC, "fullversion", ownName, JavaCompiler.fullVersion());
}
public void printHelp() {
@@ -163,39 +164,38 @@
/** Print a string that explains usage.
*/
void help() {
- Log.printLines(out, getLocalizedString("msg.usage.header", ownName));
+ log.printLines(PrefixKind.JAVAC, "msg.usage.header", ownName);
for (int i=0; i<recognizedOptions.length; i++) {
- recognizedOptions[i].help(out);
+ recognizedOptions[i].help(log);
}
- out.println();
+ log.printNewline();
}
/** Print a string that explains usage for X options.
*/
void xhelp() {
for (int i=0; i<recognizedOptions.length; i++) {
- recognizedOptions[i].xhelp(out);
+ recognizedOptions[i].xhelp(log);
}
- out.println();
- Log.printLines(out, getLocalizedString("msg.usage.nonstandard.footer"));
+ log.printNewline();
+ log.printLines(PrefixKind.JAVAC, "msg.usage.nonstandard.footer");
}
/** Report a usage error.
*/
void error(String key, Object... args) {
if (apiMode) {
- String msg = getLocalizedString(key, args);
+ String msg = log.localize(PrefixKind.JAVAC, key, args);
throw new PropagatedException(new IllegalStateException(msg));
}
warning(key, args);
- Log.printLines(out, getLocalizedString("msg.usage", ownName));
+ log.printLines(PrefixKind.JAVAC, "msg.usage", ownName);
}
/** Report a warning.
*/
void warning(String key, Object... args) {
- Log.printLines(out, ownName + ": "
- + getLocalizedString(key, args));
+ log.printRawLines(ownName + ": " + log.localize(PrefixKind.JAVAC, key, args));
}
public Option getOption(String flag) {
@@ -400,9 +400,7 @@
return Result.CMDERR;
}
} catch (java.io.FileNotFoundException e) {
- Log.printLines(out, ownName + ": " +
- getLocalizedString("err.file.not.found",
- e.getMessage()));
+ warning("err.file.not.found", e.getMessage());
return Result.SYSERR;
}
@@ -440,10 +438,10 @@
if (log.expectDiagKeys != null) {
if (log.expectDiagKeys.isEmpty()) {
- log.printLines(Log.WriterKind.NOTICE, "all expected diagnostics found");
+ log.printRawLines("all expected diagnostics found");
return Result.OK;
} else {
- log.printLines(Log.WriterKind.NOTICE, "expected diagnostic keys not found: " + log.expectDiagKeys);
+ log.printRawLines("expected diagnostic keys not found: " + log.expectDiagKeys);
return Result.ERROR;
}
}
@@ -498,52 +496,50 @@
/** Print a message reporting an internal error.
*/
void bugMessage(Throwable ex) {
- Log.printLines(out, getLocalizedString("msg.bug",
- JavaCompiler.version()));
- ex.printStackTrace(out);
+ log.printLines(PrefixKind.JAVAC, "msg.bug", JavaCompiler.version());
+ ex.printStackTrace(log.getWriter(WriterKind.NOTICE));
}
/** Print a message reporting a fatal error.
*/
void feMessage(Throwable ex) {
- Log.printLines(out, ex.getMessage());
+ log.printRawLines(ex.getMessage());
if (ex.getCause() != null && options.isSet("dev")) {
- ex.getCause().printStackTrace(out);
+ ex.getCause().printStackTrace(log.getWriter(WriterKind.NOTICE));
}
}
/** Print a message reporting an input/output error.
*/
void ioMessage(Throwable ex) {
- Log.printLines(out, getLocalizedString("msg.io"));
- ex.printStackTrace(out);
+ log.printLines(PrefixKind.JAVAC, "msg.io");
+ ex.printStackTrace(log.getWriter(WriterKind.NOTICE));
}
/** Print a message reporting an out-of-resources error.
*/
void resourceMessage(Throwable ex) {
- Log.printLines(out, getLocalizedString("msg.resource"));
-// System.out.println("(name buffer len = " + Name.names.length + " " + Name.nc);//DEBUG
- ex.printStackTrace(out);
+ log.printLines(PrefixKind.JAVAC, "msg.resource");
+ ex.printStackTrace(log.getWriter(WriterKind.NOTICE));
}
/** Print a message reporting an uncaught exception from an
* annotation processor.
*/
void apMessage(AnnotationProcessingError ex) {
- Log.printLines(out,
- getLocalizedString("msg.proc.annotation.uncaught.exception"));
- ex.getCause().printStackTrace(out);
+ log.printLines("msg.proc.annotation.uncaught.exception");
+ ex.getCause().printStackTrace(log.getWriter(WriterKind.NOTICE));
}
/** Display the location and checksum of a class. */
void showClass(String className) {
- out.println("javac: show class: " + className);
+ PrintWriter pw = log.getWriter(WriterKind.NOTICE);
+ pw.println("javac: show class: " + className);
URL url = getClass().getResource('/' + className.replace('.', '/') + ".class");
if (url == null)
- out.println(" class not found");
+ pw.println(" class not found");
else {
- out.println(" " + url);
+ pw.println(" " + url);
try {
final String algorithm = "MD5";
byte[] digest;
@@ -560,9 +556,9 @@
StringBuilder sb = new StringBuilder();
for (byte b: digest)
sb.append(String.format("%02x", b));
- out.println(" " + algorithm + " checksum: " + sb);
+ pw.println(" " + algorithm + " checksum: " + sb);
} catch (Exception e) {
- out.println(" cannot compute digest: " + e);
+ pw.println(" cannot compute digest: " + e);
}
}
}
@@ -573,35 +569,35 @@
* Internationalization
*************************************************************************/
- /** Find a localized string in the resource bundle.
- * @param key The key for the localized string.
- */
- public static String getLocalizedString(String key, Object... args) { // FIXME sb private
- try {
- if (messages == null)
- messages = new JavacMessages(javacBundleName);
- return messages.getLocalizedString("javac." + key, args);
- }
- catch (MissingResourceException e) {
- throw new Error("Fatal Error: Resource for javac is missing", e);
- }
- }
+// /** Find a localized string in the resource bundle.
+// * @param key The key for the localized string.
+// */
+// public static String getLocalizedString(String key, Object... args) { // FIXME sb private
+// try {
+// if (messages == null)
+// messages = new JavacMessages(javacBundleName);
+// return messages.getLocalizedString("javac." + key, args);
+// }
+// catch (MissingResourceException e) {
+// throw new Error("Fatal Error: Resource for javac is missing", e);
+// }
+// }
+//
+// public static void useRawMessages(boolean enable) {
+// if (enable) {
+// messages = new JavacMessages(javacBundleName) {
+// @Override
+// public String getLocalizedString(String key, Object... args) {
+// return key;
+// }
+// };
+// } else {
+// messages = new JavacMessages(javacBundleName);
+// }
+// }
- public static void useRawMessages(boolean enable) {
- if (enable) {
- messages = new JavacMessages(javacBundleName) {
- @Override
- public String getLocalizedString(String key, Object... args) {
- return key;
- }
- };
- } else {
- messages = new JavacMessages(javacBundleName);
- }
- }
-
- private static final String javacBundleName =
+ public static final String javacBundleName =
"com.sun.tools.javac.resources.javac";
-
- private static JavacMessages messages;
+//
+// private static JavacMessages messages;
}
--- a/langtools/src/share/classes/com/sun/tools/javac/main/RecognizedOptions.java Tue Nov 08 17:06:08 2011 -0800
+++ b/langtools/src/share/classes/com/sun/tools/javac/main/RecognizedOptions.java Tue Nov 08 17:06:58 2011 -0800
@@ -25,16 +25,6 @@
package com.sun.tools.javac.main;
-import com.sun.tools.javac.code.Lint;
-import com.sun.tools.javac.code.Source;
-import com.sun.tools.javac.code.Type;
-import com.sun.tools.javac.jvm.Target;
-import com.sun.tools.javac.main.JavacOption.HiddenOption;
-import com.sun.tools.javac.main.JavacOption.Option;
-import com.sun.tools.javac.main.JavacOption.XOption;
-import com.sun.tools.javac.util.ListBuffer;
-import com.sun.tools.javac.util.Options;
-import com.sun.tools.javac.processing.JavacProcessingEnvironment;
import java.io.File;
import java.io.FileWriter;
import java.io.PrintWriter;
@@ -44,6 +34,19 @@
import java.util.Set;
import javax.lang.model.SourceVersion;
+import com.sun.tools.javac.code.Lint;
+import com.sun.tools.javac.code.Source;
+import com.sun.tools.javac.code.Type;
+import com.sun.tools.javac.jvm.Target;
+import com.sun.tools.javac.main.JavacOption.HiddenOption;
+import com.sun.tools.javac.main.JavacOption.Option;
+import com.sun.tools.javac.main.JavacOption.XOption;
+import com.sun.tools.javac.processing.JavacProcessingEnvironment;
+import com.sun.tools.javac.util.ListBuffer;
+import com.sun.tools.javac.util.Log;
+import com.sun.tools.javac.util.Log.PrefixKind;
+import com.sun.tools.javac.util.Options;
+
import static com.sun.tools.javac.main.OptionName.*;
/**
@@ -79,13 +82,18 @@
}
public static class GrumpyHelper implements OptionHelper {
+ private Log log;
+
+ public GrumpyHelper(Log log) {
+ this.log = log;
+ }
public void setOut(PrintWriter out) {
throw new IllegalArgumentException();
}
public void error(String key, Object... args) {
- throw new IllegalArgumentException(Main.getLocalizedString(key, args));
+ throw new IllegalArgumentException(log.localize(PrefixKind.JAVAC, key, args));
}
public void printVersion() {
@@ -400,9 +408,9 @@
},
new Option(A, "opt.arg.key.equals.value","opt.A") {
@Override
- String helpSynopsis() {
+ String helpSynopsis(Log log) {
hasSuffix = true;
- return super.helpSynopsis();
+ return super.helpSynopsis(log);
}
@Override
@@ -444,9 +452,9 @@
// It's actually implemented by the launcher.
new Option(J, "opt.arg.flag", "opt.J") {
@Override
- String helpSynopsis() {
+ String helpSynopsis(Log log) {
hasSuffix = true;
- return super.helpSynopsis();
+ return super.helpSynopsis(log);
}
@Override
public boolean process(Options options, String option) {
@@ -570,9 +578,9 @@
// It's actually implemented by the CommandLine class.
new Option(AT, "opt.arg.file", "opt.AT") {
@Override
- String helpSynopsis() {
+ String helpSynopsis(Log log) {
hasSuffix = true;
- return super.helpSynopsis();
+ return super.helpSynopsis(log);
}
@Override
public boolean process(Options options, String option) {
--- a/langtools/src/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java Tue Nov 08 17:06:08 2011 -0800
+++ b/langtools/src/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java Tue Nov 08 17:06:58 2011 -0800
@@ -688,7 +688,7 @@
ps.removeSupportedOptions(unmatchedProcessorOptions);
if (printProcessorInfo || verbose) {
- log.printNoteLines("x.print.processor.info",
+ log.printLines("x.print.processor.info",
ps.processor.getClass().getName(),
matchedNames.toString(),
processingResult);
@@ -1014,7 +1014,7 @@
if (printRounds || verbose) {
List<ClassSymbol> tlc = lastRound ? List.<ClassSymbol>nil() : topLevelClasses;
Set<TypeElement> ap = lastRound ? Collections.<TypeElement>emptySet() : annotationsPresent;
- log.printNoteLines("x.print.rounds",
+ log.printLines("x.print.rounds",
number,
"{" + tlc.toString(", ") + "}",
ap,
--- a/langtools/src/share/classes/com/sun/tools/javac/resources/compiler.properties Tue Nov 08 17:06:08 2011 -0800
+++ b/langtools/src/share/classes/com/sun/tools/javac/resources/compiler.properties Tue Nov 08 17:06:58 2011 -0800
@@ -792,7 +792,7 @@
compiler.err.cant.apply.diamond=\
cannot infer type arguments for {0}
-# 0: message segment, 1: message segment
+# 0: message segment or type, 1: message segment
compiler.err.cant.apply.diamond.1=\
cannot infer type arguments for {0};\n\
reason: {1}
@@ -854,7 +854,7 @@
compiler.misc.varargs.trustme.on.virtual.varargs=\
Instance method {0} is not final.
-# 0: type, 1: kind, 2: symbol
+# 0: type, 1: symbol kind, 2: symbol
compiler.misc.inaccessible.varargs.type=\
formal varargs element type {0} is not accessible from {1} {2}
@@ -1631,6 +1631,7 @@
compiler.misc.diamond.non.generic=\
cannot use ''<>'' with non-generic class {0}
+# 0: unused
compiler.misc.diamond.and.explicit.params=\
cannot use ''<>'' with explicit type parameters for constructor
@@ -1712,7 +1713,7 @@
## The second argument {1} is the location name
## The third argument {2} is the location type (only when {1} is a variable name)
-# 0: symbol kind, 1: symbol, 2: unused
+# 0: symbol kind, 1: type or symbol, 2: unused
compiler.misc.location=\
{0} {1}
@@ -1847,6 +1848,7 @@
compiler.misc.varargs.clash.with=\
{0} in {1} overrides {2} in {3}
+# 0: unused
compiler.misc.diamond.and.anon.class=\
cannot use ''<>'' with anonymous inner classes
--- a/langtools/src/share/classes/com/sun/tools/javac/util/BaseFileManager.java Tue Nov 08 17:06:08 2011 -0800
+++ b/langtools/src/share/classes/com/sun/tools/javac/util/BaseFileManager.java Tue Nov 08 17:06:58 2011 -0800
@@ -166,7 +166,7 @@
// where
private static JavacOption[] javacFileManagerOptions =
RecognizedOptions.getJavacFileManagerOptions(
- new RecognizedOptions.GrumpyHelper());
+ new RecognizedOptions.GrumpyHelper(Log.instance(new Context())));
public int isSupportedOption(String option) {
for (JavacOption o : javacFileManagerOptions) {
--- a/langtools/src/share/classes/com/sun/tools/javac/util/Log.java Tue Nov 08 17:06:08 2011 -0800
+++ b/langtools/src/share/classes/com/sun/tools/javac/util/Log.java Tue Nov 08 17:06:58 2011 -0800
@@ -25,6 +25,7 @@
package com.sun.tools.javac.util;
+import com.sun.tools.javac.main.Main;
import java.io.*;
import java.util.Arrays;
import java.util.EnumSet;
@@ -60,6 +61,19 @@
public static final Context.Key<PrintWriter> outKey =
new Context.Key<PrintWriter>();
+ /* TODO: Should unify this with prefix handling in JCDiagnostic.Factory. */
+ public enum PrefixKind {
+ JAVAC("javac."),
+ COMPILER_MISC("compiler.misc.");
+ PrefixKind(String v) {
+ value = v;
+ }
+ public String key(String k) {
+ return value + k;
+ }
+ final String value;
+ }
+
public enum WriterKind { NOTICE, WARNING, ERROR };
protected PrintWriter errWriter;
@@ -136,6 +150,7 @@
this.diagListener = dl;
messages = JavacMessages.instance(context);
+ messages.add(Main.javacBundleName);
final Options options = Options.instance(context);
initOptions(options);
@@ -313,7 +328,6 @@
public void prompt() {
if (promptOnError) {
System.err.println(localize("resume.abort"));
- char ch;
try {
while (true) {
switch (System.in.read()) {
@@ -340,7 +354,7 @@
return;
int col = source.getColumnNumber(pos, false);
- printLines(writer, line);
+ printRawLines(writer, line);
for (int i = 0; i < col - 1; i++) {
writer.print((line.charAt(i) == '\t') ? "\t" : " ");
}
@@ -348,17 +362,48 @@
writer.flush();
}
- /** Print the text of a message, translating newlines appropriately
- * for the platform.
- */
- public void printLines(WriterKind kind, String msg) {
- printLines(getWriter(kind), msg);
+ public void printNewline() {
+ noticeWriter.println();
+ }
+
+ public void printNewline(WriterKind wk) {
+ getWriter(wk).println();
+ }
+
+ public void printLines(String key, Object... args) {
+ printRawLines(noticeWriter, localize(key, args));
+ }
+
+ public void printLines(PrefixKind pk, String key, Object... args) {
+ printRawLines(noticeWriter, localize(pk, key, args));
+ }
+
+ public void printLines(WriterKind wk, String key, Object... args) {
+ printRawLines(getWriter(wk), localize(key, args));
+ }
+
+ public void printLines(WriterKind wk, PrefixKind pk, String key, Object... args) {
+ printRawLines(getWriter(wk), localize(pk, key, args));
}
/** Print the text of a message, translating newlines appropriately
* for the platform.
*/
- public static void printLines(PrintWriter writer, String msg) {
+ public void printRawLines(String msg) {
+ printRawLines(noticeWriter, msg);
+ }
+
+ /** Print the text of a message, translating newlines appropriately
+ * for the platform.
+ */
+ public void printRawLines(WriterKind kind, String msg) {
+ printRawLines(getWriter(kind), msg);
+ }
+
+ /** Print the text of a message, translating newlines appropriately
+ * for the platform.
+ */
+ public static void printRawLines(PrintWriter writer, String msg) {
int nl;
while ((nl = msg.indexOf('\n')) != -1) {
writer.println(msg.substring(0, nl));
@@ -367,30 +412,16 @@
if (msg.length() != 0) writer.println(msg);
}
- /** Print the text of a message to the errWriter stream,
- * translating newlines appropriately for the platform.
- */
- public void printErrLines(String key, Object... args) {
- printLines(errWriter, localize(key, args));
- }
-
- /** Print the text of a message to the noticeWriter stream,
- * translating newlines appropriately for the platform.
- */
- public void printNoteLines(String key, Object... args) {
- printLines(noticeWriter, localize(key, args));
- }
-
/**
* Print the localized text of a "verbose" message to the
* noticeWriter stream.
*/
public void printVerbose(String key, Object... args) {
- printLines(noticeWriter, localize("verbose." + key, args));
+ printRawLines(noticeWriter, localize("verbose." + key, args));
}
protected void directError(String key, Object... args) {
- printErrLines(key, args);
+ printRawLines(errWriter, localize(key, args));
errWriter.flush();
}
@@ -476,7 +507,7 @@
PrintWriter writer = getWriterForDiagnosticType(diag.getType());
- printLines(writer, diagFormatter.format(diag, messages.getCurrentLocale()));
+ printRawLines(writer, diagFormatter.format(diag, messages.getCurrentLocale()));
if (promptOnError) {
switch (diag.getType()) {
@@ -519,7 +550,7 @@
* @param args Fields to substitute into the string.
*/
public static String getLocalizedString(String key, Object ... args) {
- return JavacMessages.getDefaultLocalizedString("compiler.misc." + key, args);
+ return JavacMessages.getDefaultLocalizedString(PrefixKind.COMPILER_MISC.key(key), args);
}
/** Find a localized string in the resource bundle.
@@ -527,9 +558,23 @@
* @param args Fields to substitute into the string.
*/
public String localize(String key, Object... args) {
- return messages.getLocalizedString("compiler.misc." + key, args);
+ return localize(PrefixKind.COMPILER_MISC, key, args);
}
+ /** Find a localized string in the resource bundle.
+ * @param key The key for the localized string.
+ * @param args Fields to substitute into the string.
+ */
+ public String localize(PrefixKind pk, String key, Object... args) {
+ if (useRawMessages)
+ return pk.key(key);
+ else
+ return messages.getLocalizedString(pk.key(key), args);
+ }
+ // where
+ // backdoor hook for testing, should transition to use -XDrawDiagnostics
+ private static boolean useRawMessages = false;
+
/***************************************************************************
* raw error messages without internationalization; used for experimentation
* and quick prototyping
@@ -539,12 +584,12 @@
*/
private void printRawError(int pos, String msg) {
if (source == null || pos == Position.NOPOS) {
- printLines(errWriter, "error: " + msg);
+ printRawLines(errWriter, "error: " + msg);
} else {
int line = source.getLineNumber(pos);
JavaFileObject file = source.getFile();
if (file != null)
- printLines(errWriter,
+ printRawLines(errWriter,
file.getName() + ":" +
line + ": " + msg);
printErrLine(pos, errWriter);
--- a/langtools/test/tools/javac/6410653/T6410653.java Tue Nov 08 17:06:08 2011 -0800
+++ b/langtools/test/tools/javac/6410653/T6410653.java Tue Nov 08 17:06:58 2011 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2006, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -28,7 +28,7 @@
* @author Peter von der Ah\u00e9
*/
-import java.lang.reflect.Method;
+import java.lang.reflect.Field;
import java.io.File;
import java.io.ByteArrayOutputStream;
import javax.tools.*;
@@ -39,12 +39,13 @@
String source = new File(testSrc, "T6410653.java").getPath();
ClassLoader cl = ToolProvider.getSystemToolClassLoader();
Tool compiler = ToolProvider.getSystemJavaCompiler();
- Class<?> main = Class.forName("com.sun.tools.javac.main.Main", true, cl);
- Method useRawMessages = main.getMethod("useRawMessages", boolean.class);
- useRawMessages.invoke(null, true);
+ Class<?> log = Class.forName("com.sun.tools.javac.util.Log", true, cl);
+ Field useRawMessages = log.getDeclaredField("useRawMessages");
+ useRawMessages.setAccessible(true);
+ useRawMessages.setBoolean(null, true);
ByteArrayOutputStream out = new ByteArrayOutputStream();
compiler.run(null, null, out, "-d", source, source);
- useRawMessages.invoke(null, false);
+ useRawMessages.setBoolean(null, false);
if (!out.toString().equals(String.format("%s%n%s%n",
"javac: javac.err.file.not.directory",
"javac.msg.usage"))) {
--- a/langtools/test/tools/javac/diags/ArgTypeCompilerFactory.java Tue Nov 08 17:06:08 2011 -0800
+++ b/langtools/test/tools/javac/diags/ArgTypeCompilerFactory.java Tue Nov 08 17:06:58 2011 -0800
@@ -105,13 +105,11 @@
Iterable<? extends JavaFileObject> fos = fm.getJavaFileObjectsFromFiles(files);
- JavacTaskImpl t = (JavacTaskImpl) tool.getTask(out, fm, null, opts, null, fos);
- Context c = t.getContext();
+ Context c = new Context();
ArgTypeMessages.preRegister(c);
ArgTypeJavaCompiler.preRegister(c);
- Boolean ok = t.call();
-
- return ok;
+ JavacTaskImpl t = (JavacTaskImpl) tool.getTask(out, fm, null, opts, null, fos, c);
+ return t.call();
}
}