6966732: replace use of static Log.getLocalizedString with non-static alternative where possible

Tue, 13 Jul 2010 19:14:09 -0700

author
jjg
date
Tue, 13 Jul 2010 19:14:09 -0700
changeset 604
a5454419dd46
parent 598
064468702a8d
child 605
0e1fab5cffc8

6966732: replace use of static Log.getLocalizedString with non-static alternative where possible
Reviewed-by: darcy

src/share/classes/com/sun/tools/javac/jvm/ClassReader.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/jvm/ClassWriter.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/main/JavaCompiler.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/util/Log.java file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/classes/com/sun/tools/javac/jvm/ClassReader.java	Mon Jul 12 16:37:46 2010 -0700
     1.2 +++ b/src/share/classes/com/sun/tools/javac/jvm/ClassReader.java	Tue Jul 13 19:14:09 2010 -0700
     1.3 @@ -2628,7 +2628,7 @@
     1.4       *  @param arg An argument for substitution into the output string.
     1.5       */
     1.6      private void printVerbose(String key, CharSequence arg) {
     1.7 -        Log.printLines(log.noticeWriter, Log.getLocalizedString("verbose." + key, arg));
     1.8 +        log.printNoteLines("verbose." + key, arg);
     1.9      }
    1.10  
    1.11      /** Output for "-checkclassfile" option.
    1.12 @@ -2636,7 +2636,7 @@
    1.13       *  @param arg An argument for substitution into the output string.
    1.14       */
    1.15      private void printCCF(String key, Object arg) {
    1.16 -        Log.printLines(log.noticeWriter, Log.getLocalizedString(key, arg));
    1.17 +        log.printNoteLines(key, arg);
    1.18      }
    1.19  
    1.20  
     2.1 --- a/src/share/classes/com/sun/tools/javac/jvm/ClassWriter.java	Mon Jul 12 16:37:46 2010 -0700
     2.2 +++ b/src/share/classes/com/sun/tools/javac/jvm/ClassWriter.java	Tue Jul 13 19:14:09 2010 -0700
     2.3 @@ -1604,7 +1604,7 @@
     2.4          try {
     2.5              writeClassFile(out, c);
     2.6              if (verbose)
     2.7 -                log.errWriter.println(Log.getLocalizedString("verbose.wrote.file", outFile));
     2.8 +                log.printErrLines("verbose.wrote.file", outFile);
     2.9              out.close();
    2.10              out = null;
    2.11          } finally {
     3.1 --- a/src/share/classes/com/sun/tools/javac/main/JavaCompiler.java	Mon Jul 12 16:37:46 2010 -0700
     3.2 +++ b/src/share/classes/com/sun/tools/javac/main/JavaCompiler.java	Tue Jul 13 19:14:09 2010 -0700
     3.3 @@ -1105,7 +1105,7 @@
     3.4              return env;
     3.5  
     3.6          if (verboseCompilePolicy)
     3.7 -            Log.printLines(log.noticeWriter, "[attribute " + env.enclClass.sym + "]");
     3.8 +            printNote("[attribute " + env.enclClass.sym + "]");
     3.9          if (verbose)
    3.10              printVerbose("checking.attribution", env.enclClass.sym);
    3.11  
    3.12 @@ -1527,19 +1527,19 @@
    3.13       *  @param arg An argument for substitution into the output string.
    3.14       */
    3.15      protected void printVerbose(String key, Object arg) {
    3.16 -        Log.printLines(log.noticeWriter, Log.getLocalizedString("verbose." + key, arg));
    3.17 +        log.printNoteLines("verbose." + key, arg);
    3.18      }
    3.19  
    3.20      /** Print numbers of errors and warnings.
    3.21       */
    3.22      protected void printCount(String kind, int count) {
    3.23          if (count != 0) {
    3.24 -            String text;
    3.25 +            String key;
    3.26              if (count == 1)
    3.27 -                text = Log.getLocalizedString("count." + kind, String.valueOf(count));
    3.28 +                key = "count." + kind;
    3.29              else
    3.30 -                text = Log.getLocalizedString("count." + kind + ".plural", String.valueOf(count));
    3.31 -            Log.printLines(log.errWriter, text);
    3.32 +                key = "count." + kind + ".plural";
    3.33 +            log.printErrLines(key, String.valueOf(count));
    3.34              log.errWriter.flush();
    3.35          }
    3.36      }
     4.1 --- a/src/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java	Mon Jul 12 16:37:46 2010 -0700
     4.2 +++ b/src/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java	Tue Jul 13 19:14:09 2010 -0700
     4.3 @@ -654,9 +654,6 @@
     4.4                                       Set<TypeElement> annotationsPresent,
     4.5                                       List<ClassSymbol> topLevelClasses,
     4.6                                       List<PackageSymbol> packageInfoFiles) {
     4.7 -        // Writer for -XprintRounds and -XprintProcessorInfo data
     4.8 -        PrintWriter xout = context.get(Log.outKey);
     4.9 -
    4.10          Map<String, TypeElement> unmatchedAnnotations =
    4.11              new HashMap<String, TypeElement>(annotationsPresent.size());
    4.12  
    4.13 @@ -708,10 +705,10 @@
    4.14                  ps.removeSupportedOptions(unmatchedProcessorOptions);
    4.15  
    4.16                  if (printProcessorInfo || verbose) {
    4.17 -                    xout.println(Log.getLocalizedString("x.print.processor.info",
    4.18 -                                                        ps.processor.getClass().getName(),
    4.19 -                                                        matchedNames.toString(),
    4.20 -                                                        processingResult));
    4.21 +                    log.printNoteLines("x.print.processor.info",
    4.22 +                            ps.processor.getClass().getName(),
    4.23 +                            matchedNames.toString(),
    4.24 +                            processingResult);
    4.25                  }
    4.26  
    4.27                  if (processingResult) {
    4.28 @@ -795,8 +792,6 @@
    4.29          throws IOException {
    4.30  
    4.31          log = Log.instance(context);
    4.32 -        // Writer for -XprintRounds and -XprintProcessorInfo data
    4.33 -        PrintWriter xout = context.get(Log.outKey);
    4.34          TaskListener taskListener = context.get(TaskListener.class);
    4.35  
    4.36          JavaCompiler compiler = JavaCompiler.instance(context);
    4.37 @@ -839,7 +834,7 @@
    4.38  
    4.39              this.context = currentContext;
    4.40              roundNumber++;
    4.41 -            printRoundInfo(xout, roundNumber, topLevelClasses, annotationsPresent, false);
    4.42 +            printRoundInfo(roundNumber, topLevelClasses, annotationsPresent, false);
    4.43  
    4.44              if (taskListener != null)
    4.45                  taskListener.started(new TaskEvent(TaskEvent.Kind.ANNOTATION_PROCESSING_ROUND));
    4.46 @@ -908,7 +903,7 @@
    4.47                      break runAround; // No new files
    4.48              }
    4.49          }
    4.50 -        roots = runLastRound(xout, roundNumber, errorStatus, compiler, roots, taskListener);
    4.51 +        roots = runLastRound(roundNumber, errorStatus, compiler, roots, taskListener);
    4.52          // Set error status for any files compiled and generated in
    4.53          // the last round
    4.54          if (log.unrecoverableError)
    4.55 @@ -982,8 +977,7 @@
    4.56      }
    4.57  
    4.58      // Call the last round of annotation processing
    4.59 -    private List<JCCompilationUnit> runLastRound(PrintWriter xout,
    4.60 -                                                 int roundNumber,
    4.61 +    private List<JCCompilationUnit> runLastRound(int roundNumber,
    4.62                                                   boolean errorStatus,
    4.63                                                   JavaCompiler compiler,
    4.64                                                   List<JCCompilationUnit> roots,
    4.65 @@ -991,7 +985,7 @@
    4.66          roundNumber++;
    4.67          List<ClassSymbol> noTopLevelClasses = List.nil();
    4.68          Set<TypeElement> noAnnotations =  Collections.emptySet();
    4.69 -        printRoundInfo(xout, roundNumber, noTopLevelClasses, noAnnotations, true);
    4.70 +        printRoundInfo(roundNumber, noTopLevelClasses, noAnnotations, true);
    4.71  
    4.72          Set<Element> emptyRootElements = Collections.emptySet(); // immutable
    4.73          RoundEnvironment renv = new JavacRoundEnvironment(true,
    4.74 @@ -1032,17 +1026,16 @@
    4.75          }
    4.76      }
    4.77  
    4.78 -    private void printRoundInfo(PrintWriter xout,
    4.79 -                                int roundNumber,
    4.80 +    private void printRoundInfo(int roundNumber,
    4.81                                  List<ClassSymbol> topLevelClasses,
    4.82                                  Set<TypeElement> annotationsPresent,
    4.83                                  boolean lastRound) {
    4.84          if (printRounds || verbose) {
    4.85 -            xout.println(Log.getLocalizedString("x.print.rounds",
    4.86 -                                                roundNumber,
    4.87 -                                                "{" + topLevelClasses.toString(", ") + "}",
    4.88 -                                                annotationsPresent,
    4.89 -                                                lastRound));
    4.90 +            log.printNoteLines("x.print.rounds",
    4.91 +                    roundNumber,
    4.92 +                    "{" + topLevelClasses.toString(", ") + "}",
    4.93 +                    annotationsPresent,
    4.94 +                    lastRound);
    4.95          }
    4.96      }
    4.97  
     5.1 --- a/src/share/classes/com/sun/tools/javac/util/Log.java	Mon Jul 12 16:37:46 2010 -0700
     5.2 +++ b/src/share/classes/com/sun/tools/javac/util/Log.java	Tue Jul 13 19:14:09 2010 -0700
     5.3 @@ -269,7 +269,7 @@
     5.4       */
     5.5      public void prompt() {
     5.6          if (promptOnError) {
     5.7 -            System.err.println(getLocalizedString("resume.abort"));
     5.8 +            System.err.println(localize("resume.abort"));
     5.9              char ch;
    5.10              try {
    5.11                  while (true) {
    5.12 @@ -317,8 +317,23 @@
    5.13          if (msg.length() != 0) writer.println(msg);
    5.14      }
    5.15  
    5.16 +    /** Print the text of a message to the errWriter stream,
    5.17 +     *  translating newlines appropriately for the platform.
    5.18 +     */
    5.19 +    public void printErrLines(String key, Object... args) {
    5.20 +        printLines(errWriter, localize(key, args));
    5.21 +    }
    5.22 +
    5.23 +
    5.24 +    /** Print the text of a message to the noticeWriter stream,
    5.25 +     *  translating newlines appropriately for the platform.
    5.26 +     */
    5.27 +    public void printNoteLines(String key, Object... args) {
    5.28 +        printLines(noticeWriter, localize(key, args));
    5.29 +    }
    5.30 +
    5.31      protected void directError(String key, Object... args) {
    5.32 -        printLines(errWriter, getLocalizedString(key, args));
    5.33 +        printErrLines(key, args);
    5.34          errWriter.flush();
    5.35      }
    5.36  
    5.37 @@ -426,6 +441,8 @@
    5.38      }
    5.39  
    5.40      /** Find a localized string in the resource bundle.
    5.41 +     *  Because this method is static, it ignores the locale.
    5.42 +     *  Use localize(key, args) when possible.
    5.43       *  @param key    The key for the localized string.
    5.44       *  @param args   Fields to substitute into the string.
    5.45       */
    5.46 @@ -433,6 +450,14 @@
    5.47          return JavacMessages.getDefaultLocalizedString("compiler.misc." + key, args);
    5.48      }
    5.49  
    5.50 +    /** Find a localized string in the resource bundle.
    5.51 +     *  @param key    The key for the localized string.
    5.52 +     *  @param args   Fields to substitute into the string.
    5.53 +     */
    5.54 +    public String localize(String key, Object... args) {
    5.55 +        return messages.getLocalizedString("compiler.misc." + key, args);
    5.56 +    }
    5.57 +
    5.58  /***************************************************************************
    5.59   * raw error messages without internationalization; used for experimentation
    5.60   * and quick prototyping

mercurial