Tue, 08 Nov 2011 17:06:58 -0800
7108669: cleanup Log methods for direct printing to streams
Reviewed-by: mcimadamore
1.1 --- a/src/share/classes/com/sun/tools/apt/main/Main.java Tue Nov 08 17:06:08 2011 -0800 1.2 +++ b/src/share/classes/com/sun/tools/apt/main/Main.java Tue Nov 08 17:06:58 2011 -0800 1.3 @@ -205,7 +205,7 @@ 1.4 String s = " " + helpSynopsis(); 1.5 out.print(s); 1.6 for (int j = s.length(); j < 29; j++) out.print(" "); 1.7 - Bark.printLines(out, getLocalizedString(descrKey)); 1.8 + Bark.printRawLines(out, getLocalizedString(descrKey)); 1.9 } 1.10 1.11 } 1.12 @@ -227,7 +227,7 @@ 1.13 String s = " " + helpSynopsis(); 1.14 out.print(s); 1.15 for (int j = s.length(); j < 29; j++) out.print(" "); 1.16 - Bark.printLines(out, getLocalizedString(descrKey)); 1.17 + Bark.printRawLines(out, getLocalizedString(descrKey)); 1.18 } 1.19 1.20 } 1.21 @@ -259,7 +259,7 @@ 1.22 String s = " " + helpSynopsis(); 1.23 out.print(s); 1.24 for (int j = s.length(); j < 29; j++) out.print(" "); 1.25 - Log.printLines(out, getLocalizedString(descrKey)); 1.26 + Log.printRawLines(out, getLocalizedString(descrKey)); 1.27 } 1.28 }; 1.29 1.30 @@ -421,7 +421,7 @@ 1.31 }, 1.32 new AptOption("-version", "opt.version") { 1.33 boolean process(String option) { 1.34 - Bark.printLines(out, ownName + " " + AptJavaCompiler.version()); 1.35 + Bark.printRawLines(out, ownName + " " + AptJavaCompiler.version()); 1.36 return super.process(option); 1.37 } 1.38 }, 1.39 @@ -660,11 +660,11 @@ 1.40 /** Print a string that explains usage. 1.41 */ 1.42 void help() { 1.43 - Bark.printLines(out, getLocalizedString("msg.usage.header", ownName)); 1.44 + Bark.printRawLines(out, getLocalizedString("msg.usage.header", ownName)); 1.45 for (int i=0; i < recognizedOptions.length; i++) { 1.46 recognizedOptions[i].help(); 1.47 } 1.48 - Bark.printLines(out, getLocalizedString("msg.usage.footer")); 1.49 + Bark.printRawLines(out, getLocalizedString("msg.usage.footer")); 1.50 out.println(); 1.51 } 1.52 1.53 @@ -675,7 +675,7 @@ 1.54 recognizedOptions[i].xhelp(); 1.55 } 1.56 out.println(); 1.57 - Bark.printLines(out, getLocalizedString("msg.usage.nonstandard.footer")); 1.58 + Bark.printRawLines(out, getLocalizedString("msg.usage.nonstandard.footer")); 1.59 } 1.60 1.61 /** Report a usage error. 1.62 @@ -688,7 +688,7 @@ 1.63 /** Report a warning. 1.64 */ 1.65 void warning(String key, Object... args) { 1.66 - Bark.printLines(out, ownName + ": " 1.67 + Bark.printRawLines(out, ownName + ": " 1.68 + getLocalizedString(key, args)); 1.69 } 1.70 1.71 @@ -796,7 +796,7 @@ 1.72 origFilenames = processArgs((args=CommandLine.parse(args))); 1.73 1.74 if (options.get("suppress-tool-api-removal-message") == null) { 1.75 - Bark.printLines(out, getLocalizedString("misc.Deprecation")); 1.76 + Bark.printRawLines(out, getLocalizedString("misc.Deprecation")); 1.77 } 1.78 1.79 if (origFilenames == null) { 1.80 @@ -808,7 +808,7 @@ 1.81 return EXIT_OK; 1.82 } 1.83 } catch (java.io.FileNotFoundException e) { 1.84 - Bark.printLines(out, ownName + ": " + 1.85 + Bark.printRawLines(out, ownName + ": " + 1.86 getLocalizedString("err.file.not.found", 1.87 e.getMessage())); 1.88 return EXIT_SYSERR; 1.89 @@ -1183,7 +1183,7 @@ 1.90 /** Print a message reporting an internal error. 1.91 */ 1.92 void bugMessage(Throwable ex) { 1.93 - Bark.printLines(out, getLocalizedString("msg.bug", 1.94 + Bark.printRawLines(out, getLocalizedString("msg.bug", 1.95 AptJavaCompiler.version())); 1.96 ex.printStackTrace(out); 1.97 } 1.98 @@ -1191,34 +1191,34 @@ 1.99 /** Print a message reporting an fatal error. 1.100 */ 1.101 void apMessage(AnnotationProcessingError ex) { 1.102 - Bark.printLines(out, getLocalizedString("misc.Problem")); 1.103 + Bark.printRawLines(out, getLocalizedString("misc.Problem")); 1.104 ex.getCause().printStackTrace(out); 1.105 } 1.106 1.107 /** Print a message about sun.misc.Service problem. 1.108 */ 1.109 void sceMessage(sun.misc.ServiceConfigurationError ex) { 1.110 - Bark.printLines(out, getLocalizedString("misc.SunMiscService")); 1.111 + Bark.printRawLines(out, getLocalizedString("misc.SunMiscService")); 1.112 ex.printStackTrace(out); 1.113 } 1.114 1.115 /** Print a message reporting an fatal error. 1.116 */ 1.117 void feMessage(Throwable ex) { 1.118 - Bark.printLines(out, ex.toString()); 1.119 + Bark.printRawLines(out, ex.toString()); 1.120 } 1.121 1.122 /** Print a message reporting an input/output error. 1.123 */ 1.124 void ioMessage(Throwable ex) { 1.125 - Bark.printLines(out, getLocalizedString("msg.io")); 1.126 + Bark.printRawLines(out, getLocalizedString("msg.io")); 1.127 ex.printStackTrace(out); 1.128 } 1.129 1.130 /** Print a message reporting an out-of-resources error. 1.131 */ 1.132 void resourceMessage(Throwable ex) { 1.133 - Bark.printLines(out, getLocalizedString("msg.resource")); 1.134 + Bark.printRawLines(out, getLocalizedString("msg.resource")); 1.135 ex.printStackTrace(out); 1.136 } 1.137
2.1 --- a/src/share/classes/com/sun/tools/javac/api/JavacTool.java Tue Nov 08 17:06:08 2011 -0800 2.2 +++ b/src/share/classes/com/sun/tools/javac/api/JavacTool.java Tue Nov 08 17:06:58 2011 -0800 2.3 @@ -52,6 +52,7 @@ 2.4 import com.sun.tools.javac.util.ClientCodeException; 2.5 import com.sun.tools.javac.util.Context; 2.6 import com.sun.tools.javac.util.Log; 2.7 +import com.sun.tools.javac.util.Log.PrefixKind; 2.8 import com.sun.tools.javac.util.Options; 2.9 import com.sun.tools.javac.util.Pair; 2.10 2.11 @@ -156,15 +157,28 @@ 2.12 return new JavacFileManager(context, true, charset); 2.13 } 2.14 2.15 + @Override 2.16 public JavacTask getTask(Writer out, 2.17 JavaFileManager fileManager, 2.18 DiagnosticListener<? super JavaFileObject> diagnosticListener, 2.19 Iterable<String> options, 2.20 Iterable<String> classes, 2.21 - Iterable<? extends JavaFileObject> compilationUnits) 2.22 + Iterable<? extends JavaFileObject> compilationUnits) { 2.23 + Context context = new Context(); 2.24 + return getTask(out, fileManager, diagnosticListener, 2.25 + options, classes, compilationUnits, 2.26 + context); 2.27 + } 2.28 + 2.29 + public JavacTask getTask(Writer out, 2.30 + JavaFileManager fileManager, 2.31 + DiagnosticListener<? super JavaFileObject> diagnosticListener, 2.32 + Iterable<String> options, 2.33 + Iterable<String> classes, 2.34 + Iterable<? extends JavaFileObject> compilationUnits, 2.35 + Context context) 2.36 { 2.37 try { 2.38 - Context context = new Context(); 2.39 ClientCodeWrapper ccw = ClientCodeWrapper.instance(context); 2.40 2.41 final String kindMsg = "All compilation units must be of SOURCE kind"; 2.42 @@ -212,9 +226,10 @@ 2.43 return; 2.44 2.45 Options optionTable = Options.instance(context); 2.46 + Log log = Log.instance(context); 2.47 2.48 JavacOption[] recognizedOptions = 2.49 - RecognizedOptions.getJavacToolOptions(new GrumpyHelper()); 2.50 + RecognizedOptions.getJavacToolOptions(new GrumpyHelper(log)); 2.51 Iterator<String> flags = options.iterator(); 2.52 while (flags.hasNext()) { 2.53 String flag = flags.next(); 2.54 @@ -227,7 +242,7 @@ 2.55 if (fileManager.handleOption(flag, flags)) { 2.56 continue; 2.57 } else { 2.58 - String msg = Main.getLocalizedString("err.invalid.flag", flag); 2.59 + String msg = log.localize(PrefixKind.JAVAC, "err.invalid.flag", flag); 2.60 throw new IllegalArgumentException(msg); 2.61 } 2.62 } 2.63 @@ -235,7 +250,7 @@ 2.64 JavacOption option = recognizedOptions[j]; 2.65 if (option.hasArg()) { 2.66 if (!flags.hasNext()) { 2.67 - String msg = Main.getLocalizedString("err.req.arg", flag); 2.68 + String msg = log.localize(PrefixKind.JAVAC, "err.req.arg", flag); 2.69 throw new IllegalArgumentException(msg); 2.70 } 2.71 String operand = flags.next(); 2.72 @@ -269,7 +284,7 @@ 2.73 2.74 public int isSupportedOption(String option) { 2.75 JavacOption[] recognizedOptions = 2.76 - RecognizedOptions.getJavacToolOptions(new GrumpyHelper()); 2.77 + RecognizedOptions.getJavacToolOptions(new GrumpyHelper(null)); 2.78 for (JavacOption o : recognizedOptions) { 2.79 if (o.matches(option)) 2.80 return o.hasArg() ? 1 : 0;
3.1 --- a/src/share/classes/com/sun/tools/javac/jvm/ClassReader.java Tue Nov 08 17:06:08 2011 -0800 3.2 +++ b/src/share/classes/com/sun/tools/javac/jvm/ClassReader.java Tue Nov 08 17:06:58 2011 -0800 3.3 @@ -2539,7 +2539,7 @@ 3.4 * @param arg An argument for substitution into the output string. 3.5 */ 3.6 private void printCCF(String key, Object arg) { 3.7 - log.printNoteLines(key, arg); 3.8 + log.printLines(key, arg); 3.9 } 3.10 3.11
4.1 --- a/src/share/classes/com/sun/tools/javac/main/JavaCompiler.java Tue Nov 08 17:06:08 2011 -0800 4.2 +++ b/src/share/classes/com/sun/tools/javac/main/JavaCompiler.java Tue Nov 08 17:06:58 2011 -0800 4.3 @@ -48,17 +48,18 @@ 4.4 import com.sun.source.util.TaskEvent; 4.5 import com.sun.source.util.TaskListener; 4.6 4.7 -import com.sun.tools.javac.file.JavacFileManager; 4.8 -import com.sun.tools.javac.util.*; 4.9 import com.sun.tools.javac.code.*; 4.10 import com.sun.tools.javac.code.Lint.LintCategory; 4.11 import com.sun.tools.javac.code.Symbol.*; 4.12 +import com.sun.tools.javac.comp.*; 4.13 +import com.sun.tools.javac.file.JavacFileManager; 4.14 +import com.sun.tools.javac.jvm.*; 4.15 +import com.sun.tools.javac.parser.*; 4.16 +import com.sun.tools.javac.processing.*; 4.17 import com.sun.tools.javac.tree.*; 4.18 import com.sun.tools.javac.tree.JCTree.*; 4.19 -import com.sun.tools.javac.parser.*; 4.20 -import com.sun.tools.javac.comp.*; 4.21 -import com.sun.tools.javac.jvm.*; 4.22 -import com.sun.tools.javac.processing.*; 4.23 +import com.sun.tools.javac.util.*; 4.24 +import com.sun.tools.javac.util.Log.WriterKind; 4.25 4.26 import static javax.tools.StandardLocation.CLASS_OUTPUT; 4.27 import static com.sun.tools.javac.main.OptionName.*; 4.28 @@ -1602,7 +1603,7 @@ 4.29 } 4.30 4.31 protected void printNote(String lines) { 4.32 - log.printLines(Log.WriterKind.NOTICE, lines); 4.33 + log.printRawLines(Log.WriterKind.NOTICE, lines); 4.34 } 4.35 4.36 /** Print numbers of errors and warnings. 4.37 @@ -1614,7 +1615,7 @@ 4.38 key = "count." + kind; 4.39 else 4.40 key = "count." + kind + ".plural"; 4.41 - log.printErrLines(key, String.valueOf(count)); 4.42 + log.printLines(WriterKind.ERROR, key, String.valueOf(count)); 4.43 log.flush(Log.WriterKind.ERROR); 4.44 } 4.45 }
5.1 --- a/src/share/classes/com/sun/tools/javac/main/JavacOption.java Tue Nov 08 17:06:08 2011 -0800 5.2 +++ b/src/share/classes/com/sun/tools/javac/main/JavacOption.java Tue Nov 08 17:06:58 2011 -0800 5.3 @@ -1,5 +1,5 @@ 5.4 /* 5.5 - * Copyright (c) 2006, 2008, Oracle and/or its affiliates. All rights reserved. 5.6 + * Copyright (c) 2006, 2011, Oracle and/or its affiliates. All rights reserved. 5.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 5.8 * 5.9 * This code is free software; you can redistribute it and/or modify it 5.10 @@ -25,10 +25,11 @@ 5.11 5.12 package com.sun.tools.javac.main; 5.13 5.14 -import java.io.PrintWriter; 5.15 import java.util.LinkedHashMap; 5.16 import java.util.Map; 5.17 import com.sun.tools.javac.util.Log; 5.18 +import com.sun.tools.javac.util.Log.PrefixKind; 5.19 +import com.sun.tools.javac.util.Log.WriterKind; 5.20 import com.sun.tools.javac.util.Options; 5.21 5.22 /** 5.23 @@ -177,14 +178,14 @@ 5.24 /** Print a line of documentation describing this option, if standard. 5.25 * @param out the stream to which to write the documentation 5.26 */ 5.27 - void help(PrintWriter out) { 5.28 - String s = " " + helpSynopsis(); 5.29 - out.print(s); 5.30 - for (int j = Math.min(s.length(), 28); j < 29; j++) out.print(" "); 5.31 - Log.printLines(out, Main.getLocalizedString(descrKey)); 5.32 + void help(Log log) { 5.33 + log.printRawLines(WriterKind.NOTICE, 5.34 + String.format(" %-26s %s", 5.35 + helpSynopsis(log), 5.36 + log.localize(PrefixKind.JAVAC, descrKey))); 5.37 } 5.38 5.39 - String helpSynopsis() { 5.40 + String helpSynopsis(Log log) { 5.41 StringBuilder sb = new StringBuilder(); 5.42 sb.append(name); 5.43 if (argsNameKey == null) { 5.44 @@ -202,7 +203,7 @@ 5.45 } else { 5.46 if (!hasSuffix) 5.47 sb.append(" "); 5.48 - sb.append(Main.getLocalizedString(argsNameKey)); 5.49 + sb.append(log.localize(PrefixKind.JAVAC, argsNameKey)); 5.50 } 5.51 5.52 return sb.toString(); 5.53 @@ -211,7 +212,7 @@ 5.54 /** Print a line of documentation describing this option, if non-standard. 5.55 * @param out the stream to which to write the documentation 5.56 */ 5.57 - void xhelp(PrintWriter out) {} 5.58 + void xhelp(Log log) {} 5.59 5.60 /** Process the option (with arg). Return true if error detected. 5.61 */ 5.62 @@ -271,9 +272,9 @@ 5.63 super(name, descrKey, kind, choices); 5.64 } 5.65 @Override 5.66 - void help(PrintWriter out) {} 5.67 + void help(Log log) {} 5.68 @Override 5.69 - void xhelp(PrintWriter out) { super.help(out); } 5.70 + void xhelp(Log log) { super.help(log); } 5.71 @Override 5.72 public OptionKind getKind() { return OptionKind.EXTENDED; } 5.73 }; 5.74 @@ -288,9 +289,9 @@ 5.75 super(name, argsNameKey, null); 5.76 } 5.77 @Override 5.78 - void help(PrintWriter out) {} 5.79 + void help(Log log) {} 5.80 @Override 5.81 - void xhelp(PrintWriter out) {} 5.82 + void xhelp(Log log) {} 5.83 @Override 5.84 public OptionKind getKind() { return OptionKind.HIDDEN; } 5.85 };
6.1 --- a/src/share/classes/com/sun/tools/javac/main/Main.java Tue Nov 08 17:06:08 2011 -0800 6.2 +++ b/src/share/classes/com/sun/tools/javac/main/Main.java Tue Nov 08 17:06:58 2011 -0800 6.3 @@ -33,7 +33,6 @@ 6.4 import java.security.MessageDigest; 6.5 import java.util.Collection; 6.6 import java.util.LinkedHashSet; 6.7 -import java.util.MissingResourceException; 6.8 import java.util.Set; 6.9 import javax.tools.JavaFileManager; 6.10 import javax.tools.JavaFileObject; 6.11 @@ -46,6 +45,8 @@ 6.12 import com.sun.tools.javac.main.JavacOption.Option; 6.13 import com.sun.tools.javac.main.RecognizedOptions.OptionHelper; 6.14 import com.sun.tools.javac.util.*; 6.15 +import com.sun.tools.javac.util.Log.WriterKind; 6.16 +import com.sun.tools.javac.util.Log.PrefixKind; 6.17 import com.sun.tools.javac.processing.AnnotationProcessingError; 6.18 6.19 import static com.sun.tools.javac.main.OptionName.*; 6.20 @@ -110,11 +111,11 @@ 6.21 } 6.22 6.23 public void printVersion() { 6.24 - Log.printLines(out, getLocalizedString("version", ownName, JavaCompiler.version())); 6.25 + log.printLines(PrefixKind.JAVAC, "version", ownName, JavaCompiler.version()); 6.26 } 6.27 6.28 public void printFullVersion() { 6.29 - Log.printLines(out, getLocalizedString("fullVersion", ownName, JavaCompiler.fullVersion())); 6.30 + log.printLines(PrefixKind.JAVAC, "fullversion", ownName, JavaCompiler.fullVersion()); 6.31 } 6.32 6.33 public void printHelp() { 6.34 @@ -163,39 +164,38 @@ 6.35 /** Print a string that explains usage. 6.36 */ 6.37 void help() { 6.38 - Log.printLines(out, getLocalizedString("msg.usage.header", ownName)); 6.39 + log.printLines(PrefixKind.JAVAC, "msg.usage.header", ownName); 6.40 for (int i=0; i<recognizedOptions.length; i++) { 6.41 - recognizedOptions[i].help(out); 6.42 + recognizedOptions[i].help(log); 6.43 } 6.44 - out.println(); 6.45 + log.printNewline(); 6.46 } 6.47 6.48 /** Print a string that explains usage for X options. 6.49 */ 6.50 void xhelp() { 6.51 for (int i=0; i<recognizedOptions.length; i++) { 6.52 - recognizedOptions[i].xhelp(out); 6.53 + recognizedOptions[i].xhelp(log); 6.54 } 6.55 - out.println(); 6.56 - Log.printLines(out, getLocalizedString("msg.usage.nonstandard.footer")); 6.57 + log.printNewline(); 6.58 + log.printLines(PrefixKind.JAVAC, "msg.usage.nonstandard.footer"); 6.59 } 6.60 6.61 /** Report a usage error. 6.62 */ 6.63 void error(String key, Object... args) { 6.64 if (apiMode) { 6.65 - String msg = getLocalizedString(key, args); 6.66 + String msg = log.localize(PrefixKind.JAVAC, key, args); 6.67 throw new PropagatedException(new IllegalStateException(msg)); 6.68 } 6.69 warning(key, args); 6.70 - Log.printLines(out, getLocalizedString("msg.usage", ownName)); 6.71 + log.printLines(PrefixKind.JAVAC, "msg.usage", ownName); 6.72 } 6.73 6.74 /** Report a warning. 6.75 */ 6.76 void warning(String key, Object... args) { 6.77 - Log.printLines(out, ownName + ": " 6.78 - + getLocalizedString(key, args)); 6.79 + log.printRawLines(ownName + ": " + log.localize(PrefixKind.JAVAC, key, args)); 6.80 } 6.81 6.82 public Option getOption(String flag) { 6.83 @@ -400,9 +400,7 @@ 6.84 return Result.CMDERR; 6.85 } 6.86 } catch (java.io.FileNotFoundException e) { 6.87 - Log.printLines(out, ownName + ": " + 6.88 - getLocalizedString("err.file.not.found", 6.89 - e.getMessage())); 6.90 + warning("err.file.not.found", e.getMessage()); 6.91 return Result.SYSERR; 6.92 } 6.93 6.94 @@ -440,10 +438,10 @@ 6.95 6.96 if (log.expectDiagKeys != null) { 6.97 if (log.expectDiagKeys.isEmpty()) { 6.98 - log.printLines(Log.WriterKind.NOTICE, "all expected diagnostics found"); 6.99 + log.printRawLines("all expected diagnostics found"); 6.100 return Result.OK; 6.101 } else { 6.102 - log.printLines(Log.WriterKind.NOTICE, "expected diagnostic keys not found: " + log.expectDiagKeys); 6.103 + log.printRawLines("expected diagnostic keys not found: " + log.expectDiagKeys); 6.104 return Result.ERROR; 6.105 } 6.106 } 6.107 @@ -498,52 +496,50 @@ 6.108 /** Print a message reporting an internal error. 6.109 */ 6.110 void bugMessage(Throwable ex) { 6.111 - Log.printLines(out, getLocalizedString("msg.bug", 6.112 - JavaCompiler.version())); 6.113 - ex.printStackTrace(out); 6.114 + log.printLines(PrefixKind.JAVAC, "msg.bug", JavaCompiler.version()); 6.115 + ex.printStackTrace(log.getWriter(WriterKind.NOTICE)); 6.116 } 6.117 6.118 /** Print a message reporting a fatal error. 6.119 */ 6.120 void feMessage(Throwable ex) { 6.121 - Log.printLines(out, ex.getMessage()); 6.122 + log.printRawLines(ex.getMessage()); 6.123 if (ex.getCause() != null && options.isSet("dev")) { 6.124 - ex.getCause().printStackTrace(out); 6.125 + ex.getCause().printStackTrace(log.getWriter(WriterKind.NOTICE)); 6.126 } 6.127 } 6.128 6.129 /** Print a message reporting an input/output error. 6.130 */ 6.131 void ioMessage(Throwable ex) { 6.132 - Log.printLines(out, getLocalizedString("msg.io")); 6.133 - ex.printStackTrace(out); 6.134 + log.printLines(PrefixKind.JAVAC, "msg.io"); 6.135 + ex.printStackTrace(log.getWriter(WriterKind.NOTICE)); 6.136 } 6.137 6.138 /** Print a message reporting an out-of-resources error. 6.139 */ 6.140 void resourceMessage(Throwable ex) { 6.141 - Log.printLines(out, getLocalizedString("msg.resource")); 6.142 -// System.out.println("(name buffer len = " + Name.names.length + " " + Name.nc);//DEBUG 6.143 - ex.printStackTrace(out); 6.144 + log.printLines(PrefixKind.JAVAC, "msg.resource"); 6.145 + ex.printStackTrace(log.getWriter(WriterKind.NOTICE)); 6.146 } 6.147 6.148 /** Print a message reporting an uncaught exception from an 6.149 * annotation processor. 6.150 */ 6.151 void apMessage(AnnotationProcessingError ex) { 6.152 - Log.printLines(out, 6.153 - getLocalizedString("msg.proc.annotation.uncaught.exception")); 6.154 - ex.getCause().printStackTrace(out); 6.155 + log.printLines("msg.proc.annotation.uncaught.exception"); 6.156 + ex.getCause().printStackTrace(log.getWriter(WriterKind.NOTICE)); 6.157 } 6.158 6.159 /** Display the location and checksum of a class. */ 6.160 void showClass(String className) { 6.161 - out.println("javac: show class: " + className); 6.162 + PrintWriter pw = log.getWriter(WriterKind.NOTICE); 6.163 + pw.println("javac: show class: " + className); 6.164 URL url = getClass().getResource('/' + className.replace('.', '/') + ".class"); 6.165 if (url == null) 6.166 - out.println(" class not found"); 6.167 + pw.println(" class not found"); 6.168 else { 6.169 - out.println(" " + url); 6.170 + pw.println(" " + url); 6.171 try { 6.172 final String algorithm = "MD5"; 6.173 byte[] digest; 6.174 @@ -560,9 +556,9 @@ 6.175 StringBuilder sb = new StringBuilder(); 6.176 for (byte b: digest) 6.177 sb.append(String.format("%02x", b)); 6.178 - out.println(" " + algorithm + " checksum: " + sb); 6.179 + pw.println(" " + algorithm + " checksum: " + sb); 6.180 } catch (Exception e) { 6.181 - out.println(" cannot compute digest: " + e); 6.182 + pw.println(" cannot compute digest: " + e); 6.183 } 6.184 } 6.185 } 6.186 @@ -573,35 +569,35 @@ 6.187 * Internationalization 6.188 *************************************************************************/ 6.189 6.190 - /** Find a localized string in the resource bundle. 6.191 - * @param key The key for the localized string. 6.192 - */ 6.193 - public static String getLocalizedString(String key, Object... args) { // FIXME sb private 6.194 - try { 6.195 - if (messages == null) 6.196 - messages = new JavacMessages(javacBundleName); 6.197 - return messages.getLocalizedString("javac." + key, args); 6.198 - } 6.199 - catch (MissingResourceException e) { 6.200 - throw new Error("Fatal Error: Resource for javac is missing", e); 6.201 - } 6.202 - } 6.203 +// /** Find a localized string in the resource bundle. 6.204 +// * @param key The key for the localized string. 6.205 +// */ 6.206 +// public static String getLocalizedString(String key, Object... args) { // FIXME sb private 6.207 +// try { 6.208 +// if (messages == null) 6.209 +// messages = new JavacMessages(javacBundleName); 6.210 +// return messages.getLocalizedString("javac." + key, args); 6.211 +// } 6.212 +// catch (MissingResourceException e) { 6.213 +// throw new Error("Fatal Error: Resource for javac is missing", e); 6.214 +// } 6.215 +// } 6.216 +// 6.217 +// public static void useRawMessages(boolean enable) { 6.218 +// if (enable) { 6.219 +// messages = new JavacMessages(javacBundleName) { 6.220 +// @Override 6.221 +// public String getLocalizedString(String key, Object... args) { 6.222 +// return key; 6.223 +// } 6.224 +// }; 6.225 +// } else { 6.226 +// messages = new JavacMessages(javacBundleName); 6.227 +// } 6.228 +// } 6.229 6.230 - public static void useRawMessages(boolean enable) { 6.231 - if (enable) { 6.232 - messages = new JavacMessages(javacBundleName) { 6.233 - @Override 6.234 - public String getLocalizedString(String key, Object... args) { 6.235 - return key; 6.236 - } 6.237 - }; 6.238 - } else { 6.239 - messages = new JavacMessages(javacBundleName); 6.240 - } 6.241 - } 6.242 - 6.243 - private static final String javacBundleName = 6.244 + public static final String javacBundleName = 6.245 "com.sun.tools.javac.resources.javac"; 6.246 - 6.247 - private static JavacMessages messages; 6.248 +// 6.249 +// private static JavacMessages messages; 6.250 }
7.1 --- a/src/share/classes/com/sun/tools/javac/main/RecognizedOptions.java Tue Nov 08 17:06:08 2011 -0800 7.2 +++ b/src/share/classes/com/sun/tools/javac/main/RecognizedOptions.java Tue Nov 08 17:06:58 2011 -0800 7.3 @@ -25,16 +25,6 @@ 7.4 7.5 package com.sun.tools.javac.main; 7.6 7.7 -import com.sun.tools.javac.code.Lint; 7.8 -import com.sun.tools.javac.code.Source; 7.9 -import com.sun.tools.javac.code.Type; 7.10 -import com.sun.tools.javac.jvm.Target; 7.11 -import com.sun.tools.javac.main.JavacOption.HiddenOption; 7.12 -import com.sun.tools.javac.main.JavacOption.Option; 7.13 -import com.sun.tools.javac.main.JavacOption.XOption; 7.14 -import com.sun.tools.javac.util.ListBuffer; 7.15 -import com.sun.tools.javac.util.Options; 7.16 -import com.sun.tools.javac.processing.JavacProcessingEnvironment; 7.17 import java.io.File; 7.18 import java.io.FileWriter; 7.19 import java.io.PrintWriter; 7.20 @@ -44,6 +34,19 @@ 7.21 import java.util.Set; 7.22 import javax.lang.model.SourceVersion; 7.23 7.24 +import com.sun.tools.javac.code.Lint; 7.25 +import com.sun.tools.javac.code.Source; 7.26 +import com.sun.tools.javac.code.Type; 7.27 +import com.sun.tools.javac.jvm.Target; 7.28 +import com.sun.tools.javac.main.JavacOption.HiddenOption; 7.29 +import com.sun.tools.javac.main.JavacOption.Option; 7.30 +import com.sun.tools.javac.main.JavacOption.XOption; 7.31 +import com.sun.tools.javac.processing.JavacProcessingEnvironment; 7.32 +import com.sun.tools.javac.util.ListBuffer; 7.33 +import com.sun.tools.javac.util.Log; 7.34 +import com.sun.tools.javac.util.Log.PrefixKind; 7.35 +import com.sun.tools.javac.util.Options; 7.36 + 7.37 import static com.sun.tools.javac.main.OptionName.*; 7.38 7.39 /** 7.40 @@ -79,13 +82,18 @@ 7.41 } 7.42 7.43 public static class GrumpyHelper implements OptionHelper { 7.44 + private Log log; 7.45 + 7.46 + public GrumpyHelper(Log log) { 7.47 + this.log = log; 7.48 + } 7.49 7.50 public void setOut(PrintWriter out) { 7.51 throw new IllegalArgumentException(); 7.52 } 7.53 7.54 public void error(String key, Object... args) { 7.55 - throw new IllegalArgumentException(Main.getLocalizedString(key, args)); 7.56 + throw new IllegalArgumentException(log.localize(PrefixKind.JAVAC, key, args)); 7.57 } 7.58 7.59 public void printVersion() { 7.60 @@ -400,9 +408,9 @@ 7.61 }, 7.62 new Option(A, "opt.arg.key.equals.value","opt.A") { 7.63 @Override 7.64 - String helpSynopsis() { 7.65 + String helpSynopsis(Log log) { 7.66 hasSuffix = true; 7.67 - return super.helpSynopsis(); 7.68 + return super.helpSynopsis(log); 7.69 } 7.70 7.71 @Override 7.72 @@ -444,9 +452,9 @@ 7.73 // It's actually implemented by the launcher. 7.74 new Option(J, "opt.arg.flag", "opt.J") { 7.75 @Override 7.76 - String helpSynopsis() { 7.77 + String helpSynopsis(Log log) { 7.78 hasSuffix = true; 7.79 - return super.helpSynopsis(); 7.80 + return super.helpSynopsis(log); 7.81 } 7.82 @Override 7.83 public boolean process(Options options, String option) { 7.84 @@ -570,9 +578,9 @@ 7.85 // It's actually implemented by the CommandLine class. 7.86 new Option(AT, "opt.arg.file", "opt.AT") { 7.87 @Override 7.88 - String helpSynopsis() { 7.89 + String helpSynopsis(Log log) { 7.90 hasSuffix = true; 7.91 - return super.helpSynopsis(); 7.92 + return super.helpSynopsis(log); 7.93 } 7.94 @Override 7.95 public boolean process(Options options, String option) {
8.1 --- a/src/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java Tue Nov 08 17:06:08 2011 -0800 8.2 +++ b/src/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java Tue Nov 08 17:06:58 2011 -0800 8.3 @@ -688,7 +688,7 @@ 8.4 ps.removeSupportedOptions(unmatchedProcessorOptions); 8.5 8.6 if (printProcessorInfo || verbose) { 8.7 - log.printNoteLines("x.print.processor.info", 8.8 + log.printLines("x.print.processor.info", 8.9 ps.processor.getClass().getName(), 8.10 matchedNames.toString(), 8.11 processingResult); 8.12 @@ -1014,7 +1014,7 @@ 8.13 if (printRounds || verbose) { 8.14 List<ClassSymbol> tlc = lastRound ? List.<ClassSymbol>nil() : topLevelClasses; 8.15 Set<TypeElement> ap = lastRound ? Collections.<TypeElement>emptySet() : annotationsPresent; 8.16 - log.printNoteLines("x.print.rounds", 8.17 + log.printLines("x.print.rounds", 8.18 number, 8.19 "{" + tlc.toString(", ") + "}", 8.20 ap,
9.1 --- a/src/share/classes/com/sun/tools/javac/resources/compiler.properties Tue Nov 08 17:06:08 2011 -0800 9.2 +++ b/src/share/classes/com/sun/tools/javac/resources/compiler.properties Tue Nov 08 17:06:58 2011 -0800 9.3 @@ -792,7 +792,7 @@ 9.4 compiler.err.cant.apply.diamond=\ 9.5 cannot infer type arguments for {0} 9.6 9.7 -# 0: message segment, 1: message segment 9.8 +# 0: message segment or type, 1: message segment 9.9 compiler.err.cant.apply.diamond.1=\ 9.10 cannot infer type arguments for {0};\n\ 9.11 reason: {1} 9.12 @@ -854,7 +854,7 @@ 9.13 compiler.misc.varargs.trustme.on.virtual.varargs=\ 9.14 Instance method {0} is not final. 9.15 9.16 -# 0: type, 1: kind, 2: symbol 9.17 +# 0: type, 1: symbol kind, 2: symbol 9.18 compiler.misc.inaccessible.varargs.type=\ 9.19 formal varargs element type {0} is not accessible from {1} {2} 9.20 9.21 @@ -1631,6 +1631,7 @@ 9.22 compiler.misc.diamond.non.generic=\ 9.23 cannot use ''<>'' with non-generic class {0} 9.24 9.25 +# 0: unused 9.26 compiler.misc.diamond.and.explicit.params=\ 9.27 cannot use ''<>'' with explicit type parameters for constructor 9.28 9.29 @@ -1712,7 +1713,7 @@ 9.30 ## The second argument {1} is the location name 9.31 ## The third argument {2} is the location type (only when {1} is a variable name) 9.32 9.33 -# 0: symbol kind, 1: symbol, 2: unused 9.34 +# 0: symbol kind, 1: type or symbol, 2: unused 9.35 compiler.misc.location=\ 9.36 {0} {1} 9.37 9.38 @@ -1847,6 +1848,7 @@ 9.39 compiler.misc.varargs.clash.with=\ 9.40 {0} in {1} overrides {2} in {3} 9.41 9.42 +# 0: unused 9.43 compiler.misc.diamond.and.anon.class=\ 9.44 cannot use ''<>'' with anonymous inner classes 9.45
10.1 --- a/src/share/classes/com/sun/tools/javac/util/BaseFileManager.java Tue Nov 08 17:06:08 2011 -0800 10.2 +++ b/src/share/classes/com/sun/tools/javac/util/BaseFileManager.java Tue Nov 08 17:06:58 2011 -0800 10.3 @@ -166,7 +166,7 @@ 10.4 // where 10.5 private static JavacOption[] javacFileManagerOptions = 10.6 RecognizedOptions.getJavacFileManagerOptions( 10.7 - new RecognizedOptions.GrumpyHelper()); 10.8 + new RecognizedOptions.GrumpyHelper(Log.instance(new Context()))); 10.9 10.10 public int isSupportedOption(String option) { 10.11 for (JavacOption o : javacFileManagerOptions) {
11.1 --- a/src/share/classes/com/sun/tools/javac/util/Log.java Tue Nov 08 17:06:08 2011 -0800 11.2 +++ b/src/share/classes/com/sun/tools/javac/util/Log.java Tue Nov 08 17:06:58 2011 -0800 11.3 @@ -25,6 +25,7 @@ 11.4 11.5 package com.sun.tools.javac.util; 11.6 11.7 +import com.sun.tools.javac.main.Main; 11.8 import java.io.*; 11.9 import java.util.Arrays; 11.10 import java.util.EnumSet; 11.11 @@ -60,6 +61,19 @@ 11.12 public static final Context.Key<PrintWriter> outKey = 11.13 new Context.Key<PrintWriter>(); 11.14 11.15 + /* TODO: Should unify this with prefix handling in JCDiagnostic.Factory. */ 11.16 + public enum PrefixKind { 11.17 + JAVAC("javac."), 11.18 + COMPILER_MISC("compiler.misc."); 11.19 + PrefixKind(String v) { 11.20 + value = v; 11.21 + } 11.22 + public String key(String k) { 11.23 + return value + k; 11.24 + } 11.25 + final String value; 11.26 + } 11.27 + 11.28 public enum WriterKind { NOTICE, WARNING, ERROR }; 11.29 11.30 protected PrintWriter errWriter; 11.31 @@ -136,6 +150,7 @@ 11.32 this.diagListener = dl; 11.33 11.34 messages = JavacMessages.instance(context); 11.35 + messages.add(Main.javacBundleName); 11.36 11.37 final Options options = Options.instance(context); 11.38 initOptions(options); 11.39 @@ -313,7 +328,6 @@ 11.40 public void prompt() { 11.41 if (promptOnError) { 11.42 System.err.println(localize("resume.abort")); 11.43 - char ch; 11.44 try { 11.45 while (true) { 11.46 switch (System.in.read()) { 11.47 @@ -340,7 +354,7 @@ 11.48 return; 11.49 int col = source.getColumnNumber(pos, false); 11.50 11.51 - printLines(writer, line); 11.52 + printRawLines(writer, line); 11.53 for (int i = 0; i < col - 1; i++) { 11.54 writer.print((line.charAt(i) == '\t') ? "\t" : " "); 11.55 } 11.56 @@ -348,17 +362,48 @@ 11.57 writer.flush(); 11.58 } 11.59 11.60 - /** Print the text of a message, translating newlines appropriately 11.61 - * for the platform. 11.62 - */ 11.63 - public void printLines(WriterKind kind, String msg) { 11.64 - printLines(getWriter(kind), msg); 11.65 + public void printNewline() { 11.66 + noticeWriter.println(); 11.67 + } 11.68 + 11.69 + public void printNewline(WriterKind wk) { 11.70 + getWriter(wk).println(); 11.71 + } 11.72 + 11.73 + public void printLines(String key, Object... args) { 11.74 + printRawLines(noticeWriter, localize(key, args)); 11.75 + } 11.76 + 11.77 + public void printLines(PrefixKind pk, String key, Object... args) { 11.78 + printRawLines(noticeWriter, localize(pk, key, args)); 11.79 + } 11.80 + 11.81 + public void printLines(WriterKind wk, String key, Object... args) { 11.82 + printRawLines(getWriter(wk), localize(key, args)); 11.83 + } 11.84 + 11.85 + public void printLines(WriterKind wk, PrefixKind pk, String key, Object... args) { 11.86 + printRawLines(getWriter(wk), localize(pk, key, args)); 11.87 } 11.88 11.89 /** Print the text of a message, translating newlines appropriately 11.90 * for the platform. 11.91 */ 11.92 - public static void printLines(PrintWriter writer, String msg) { 11.93 + public void printRawLines(String msg) { 11.94 + printRawLines(noticeWriter, msg); 11.95 + } 11.96 + 11.97 + /** Print the text of a message, translating newlines appropriately 11.98 + * for the platform. 11.99 + */ 11.100 + public void printRawLines(WriterKind kind, String msg) { 11.101 + printRawLines(getWriter(kind), msg); 11.102 + } 11.103 + 11.104 + /** Print the text of a message, translating newlines appropriately 11.105 + * for the platform. 11.106 + */ 11.107 + public static void printRawLines(PrintWriter writer, String msg) { 11.108 int nl; 11.109 while ((nl = msg.indexOf('\n')) != -1) { 11.110 writer.println(msg.substring(0, nl)); 11.111 @@ -367,30 +412,16 @@ 11.112 if (msg.length() != 0) writer.println(msg); 11.113 } 11.114 11.115 - /** Print the text of a message to the errWriter stream, 11.116 - * translating newlines appropriately for the platform. 11.117 - */ 11.118 - public void printErrLines(String key, Object... args) { 11.119 - printLines(errWriter, localize(key, args)); 11.120 - } 11.121 - 11.122 - /** Print the text of a message to the noticeWriter stream, 11.123 - * translating newlines appropriately for the platform. 11.124 - */ 11.125 - public void printNoteLines(String key, Object... args) { 11.126 - printLines(noticeWriter, localize(key, args)); 11.127 - } 11.128 - 11.129 /** 11.130 * Print the localized text of a "verbose" message to the 11.131 * noticeWriter stream. 11.132 */ 11.133 public void printVerbose(String key, Object... args) { 11.134 - printLines(noticeWriter, localize("verbose." + key, args)); 11.135 + printRawLines(noticeWriter, localize("verbose." + key, args)); 11.136 } 11.137 11.138 protected void directError(String key, Object... args) { 11.139 - printErrLines(key, args); 11.140 + printRawLines(errWriter, localize(key, args)); 11.141 errWriter.flush(); 11.142 } 11.143 11.144 @@ -476,7 +507,7 @@ 11.145 11.146 PrintWriter writer = getWriterForDiagnosticType(diag.getType()); 11.147 11.148 - printLines(writer, diagFormatter.format(diag, messages.getCurrentLocale())); 11.149 + printRawLines(writer, diagFormatter.format(diag, messages.getCurrentLocale())); 11.150 11.151 if (promptOnError) { 11.152 switch (diag.getType()) { 11.153 @@ -519,7 +550,7 @@ 11.154 * @param args Fields to substitute into the string. 11.155 */ 11.156 public static String getLocalizedString(String key, Object ... args) { 11.157 - return JavacMessages.getDefaultLocalizedString("compiler.misc." + key, args); 11.158 + return JavacMessages.getDefaultLocalizedString(PrefixKind.COMPILER_MISC.key(key), args); 11.159 } 11.160 11.161 /** Find a localized string in the resource bundle. 11.162 @@ -527,9 +558,23 @@ 11.163 * @param args Fields to substitute into the string. 11.164 */ 11.165 public String localize(String key, Object... args) { 11.166 - return messages.getLocalizedString("compiler.misc." + key, args); 11.167 + return localize(PrefixKind.COMPILER_MISC, key, args); 11.168 } 11.169 11.170 + /** Find a localized string in the resource bundle. 11.171 + * @param key The key for the localized string. 11.172 + * @param args Fields to substitute into the string. 11.173 + */ 11.174 + public String localize(PrefixKind pk, String key, Object... args) { 11.175 + if (useRawMessages) 11.176 + return pk.key(key); 11.177 + else 11.178 + return messages.getLocalizedString(pk.key(key), args); 11.179 + } 11.180 + // where 11.181 + // backdoor hook for testing, should transition to use -XDrawDiagnostics 11.182 + private static boolean useRawMessages = false; 11.183 + 11.184 /*************************************************************************** 11.185 * raw error messages without internationalization; used for experimentation 11.186 * and quick prototyping 11.187 @@ -539,12 +584,12 @@ 11.188 */ 11.189 private void printRawError(int pos, String msg) { 11.190 if (source == null || pos == Position.NOPOS) { 11.191 - printLines(errWriter, "error: " + msg); 11.192 + printRawLines(errWriter, "error: " + msg); 11.193 } else { 11.194 int line = source.getLineNumber(pos); 11.195 JavaFileObject file = source.getFile(); 11.196 if (file != null) 11.197 - printLines(errWriter, 11.198 + printRawLines(errWriter, 11.199 file.getName() + ":" + 11.200 line + ": " + msg); 11.201 printErrLine(pos, errWriter);
12.1 --- a/test/tools/javac/6410653/T6410653.java Tue Nov 08 17:06:08 2011 -0800 12.2 +++ b/test/tools/javac/6410653/T6410653.java Tue Nov 08 17:06:58 2011 -0800 12.3 @@ -1,5 +1,5 @@ 12.4 /* 12.5 - * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved. 12.6 + * Copyright (c) 2006, 2011, Oracle and/or its affiliates. All rights reserved. 12.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 12.8 * 12.9 * This code is free software; you can redistribute it and/or modify it 12.10 @@ -28,7 +28,7 @@ 12.11 * @author Peter von der Ah\u00e9 12.12 */ 12.13 12.14 -import java.lang.reflect.Method; 12.15 +import java.lang.reflect.Field; 12.16 import java.io.File; 12.17 import java.io.ByteArrayOutputStream; 12.18 import javax.tools.*; 12.19 @@ -39,12 +39,13 @@ 12.20 String source = new File(testSrc, "T6410653.java").getPath(); 12.21 ClassLoader cl = ToolProvider.getSystemToolClassLoader(); 12.22 Tool compiler = ToolProvider.getSystemJavaCompiler(); 12.23 - Class<?> main = Class.forName("com.sun.tools.javac.main.Main", true, cl); 12.24 - Method useRawMessages = main.getMethod("useRawMessages", boolean.class); 12.25 - useRawMessages.invoke(null, true); 12.26 + Class<?> log = Class.forName("com.sun.tools.javac.util.Log", true, cl); 12.27 + Field useRawMessages = log.getDeclaredField("useRawMessages"); 12.28 + useRawMessages.setAccessible(true); 12.29 + useRawMessages.setBoolean(null, true); 12.30 ByteArrayOutputStream out = new ByteArrayOutputStream(); 12.31 compiler.run(null, null, out, "-d", source, source); 12.32 - useRawMessages.invoke(null, false); 12.33 + useRawMessages.setBoolean(null, false); 12.34 if (!out.toString().equals(String.format("%s%n%s%n", 12.35 "javac: javac.err.file.not.directory", 12.36 "javac.msg.usage"))) {
13.1 --- a/test/tools/javac/diags/ArgTypeCompilerFactory.java Tue Nov 08 17:06:08 2011 -0800 13.2 +++ b/test/tools/javac/diags/ArgTypeCompilerFactory.java Tue Nov 08 17:06:58 2011 -0800 13.3 @@ -105,13 +105,11 @@ 13.4 13.5 Iterable<? extends JavaFileObject> fos = fm.getJavaFileObjectsFromFiles(files); 13.6 13.7 - JavacTaskImpl t = (JavacTaskImpl) tool.getTask(out, fm, null, opts, null, fos); 13.8 - Context c = t.getContext(); 13.9 + Context c = new Context(); 13.10 ArgTypeMessages.preRegister(c); 13.11 ArgTypeJavaCompiler.preRegister(c); 13.12 - Boolean ok = t.call(); 13.13 - 13.14 - return ok; 13.15 + JavacTaskImpl t = (JavacTaskImpl) tool.getTask(out, fm, null, opts, null, fos, c); 13.16 + return t.call(); 13.17 } 13.18 } 13.19