langtools/src/share/classes/com/sun/tools/javac/util/Log.java
changeset 1471 57506cdfb7b4
parent 1109 853d8c191eac
child 1472 1e09e143438c
equal deleted inserted replaced
1470:6ff8524783fa 1471:57506cdfb7b4
    27 
    27 
    28 import java.io.*;
    28 import java.io.*;
    29 import java.util.HashSet;
    29 import java.util.HashSet;
    30 import java.util.Map;
    30 import java.util.Map;
    31 import java.util.Set;
    31 import java.util.Set;
    32 import java.util.Locale;
       
    33 import javax.tools.DiagnosticListener;
    32 import javax.tools.DiagnosticListener;
    34 import javax.tools.JavaFileObject;
    33 import javax.tools.JavaFileObject;
    35 
    34 
    36 import com.sun.tools.javac.file.JavacFileManager;
    35 import com.sun.tools.javac.file.JavacFileManager;
    37 import com.sun.tools.javac.tree.JCTree;
    36 import com.sun.tools.javac.tree.JCTree;
    95     /**
    94     /**
    96      * Formatter for diagnostics
    95      * Formatter for diagnostics
    97      */
    96      */
    98     private DiagnosticFormatter<JCDiagnostic> diagFormatter;
    97     private DiagnosticFormatter<JCDiagnostic> diagFormatter;
    99 
    98 
       
    99     /**
       
   100      * JavacMessages object used for localization
       
   101      */
       
   102     private JavacMessages messages;
       
   103 
   100     /** Construct a log with given I/O redirections.
   104     /** Construct a log with given I/O redirections.
   101      */
   105      */
   102     @Deprecated
   106     @Deprecated
   103     protected Log(Context context, PrintWriter errWriter, PrintWriter warnWriter, PrintWriter noticeWriter) {
   107     protected Log(Context context, PrintWriter errWriter, PrintWriter warnWriter, PrintWriter noticeWriter) {
   104         super(JCDiagnostic.Factory.instance(context));
   108         super(JCDiagnostic.Factory.instance(context));
   113         this.emitWarnings = options.get("-Xlint:none") == null;
   117         this.emitWarnings = options.get("-Xlint:none") == null;
   114         this.MaxErrors = getIntOption(options, "-Xmaxerrs", 100);
   118         this.MaxErrors = getIntOption(options, "-Xmaxerrs", 100);
   115         this.MaxWarnings = getIntOption(options, "-Xmaxwarns", 100);
   119         this.MaxWarnings = getIntOption(options, "-Xmaxwarns", 100);
   116 
   120 
   117         boolean rawDiagnostics = options.get("rawDiagnostics") != null;
   121         boolean rawDiagnostics = options.get("rawDiagnostics") != null;
   118         Messages msgs = Messages.instance(context);
   122         messages = JavacMessages.instance(context);
   119         this.diagFormatter = rawDiagnostics ? new RawDiagnosticFormatter(msgs) :
   123         this.diagFormatter = rawDiagnostics ? new RawDiagnosticFormatter(messages) :
   120                                               new BasicDiagnosticFormatter(options, msgs);
   124                                               new BasicDiagnosticFormatter(options, messages);
   121         @SuppressWarnings("unchecked") // FIXME
   125         @SuppressWarnings("unchecked") // FIXME
   122         DiagnosticListener<? super JavaFileObject> diagListener =
   126         DiagnosticListener<? super JavaFileObject> diagListener =
   123             context.get(DiagnosticListener.class);
   127             context.get(DiagnosticListener.class);
   124         this.diagListener = diagListener;
   128         this.diagListener = diagListener;
   125     }
   129     }
   333             }
   337             }
   334         }
   338         }
   335 
   339 
   336         PrintWriter writer = getWriterForDiagnosticType(diag.getType());
   340         PrintWriter writer = getWriterForDiagnosticType(diag.getType());
   337 
   341 
   338         printLines(writer, diagFormatter.format(diag, Locale.getDefault()));
   342         printLines(writer, diagFormatter.format(diag, messages.getCurrentLocale()));
   339         if (diagFormatter.displaySource(diag)) {
   343         if (diagFormatter.displaySource(diag)) {
   340             int pos = diag.getIntPosition();
   344             int pos = diag.getIntPosition();
   341             if (pos != Position.NOPOS) {
   345             if (pos != Position.NOPOS) {
   342                 JavaFileObject prev = useSource(diag.getSource());
   346                 JavaFileObject prev = useSource(diag.getSource());
   343                 printErrLine(pos, writer);
   347                 printErrLine(pos, writer);
   382     /** Find a localized string in the resource bundle.
   386     /** Find a localized string in the resource bundle.
   383      *  @param key    The key for the localized string.
   387      *  @param key    The key for the localized string.
   384      *  @param args   Fields to substitute into the string.
   388      *  @param args   Fields to substitute into the string.
   385      */
   389      */
   386     public static String getLocalizedString(String key, Object ... args) {
   390     public static String getLocalizedString(String key, Object ... args) {
   387         return Messages.getDefaultLocalizedString("compiler.misc." + key, args);
   391         return JavacMessages.getDefaultLocalizedString("compiler.misc." + key, args);
   388     }
   392     }
   389 
   393 
   390 /***************************************************************************
   394 /***************************************************************************
   391  * raw error messages without internationalization; used for experimentation
   395  * raw error messages without internationalization; used for experimentation
   392  * and quick prototyping
   396  * and quick prototyping