src/share/classes/com/sun/tools/javac/util/Log.java

changeset 60
29d2485c1085
parent 50
b9bcea8bbe24
child 62
07c916ecfc71
     1.1 --- a/src/share/classes/com/sun/tools/javac/util/Log.java	Fri Jun 20 11:25:03 2008 +0100
     1.2 +++ b/src/share/classes/com/sun/tools/javac/util/Log.java	Wed Jun 25 14:24:53 2008 -0700
     1.3 @@ -34,7 +34,6 @@
     1.4  import javax.tools.DiagnosticListener;
     1.5  import javax.tools.JavaFileObject;
     1.6  
     1.7 -import com.sun.tools.javac.code.Source;
     1.8  import com.sun.tools.javac.file.JavacFileManager;
     1.9  import com.sun.tools.javac.tree.JCTree;
    1.10  import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
    1.11 @@ -86,10 +85,6 @@
    1.12       */
    1.13      public boolean emitWarnings;
    1.14  
    1.15 -    /** Enforce mandatory warnings.
    1.16 -     */
    1.17 -    private boolean enforceMandatoryWarnings;
    1.18 -
    1.19      /** Print stack trace on errors?
    1.20       */
    1.21      public boolean dumpOnError;
    1.22 @@ -138,9 +133,6 @@
    1.23          DiagnosticListener<? super JavaFileObject> diagListener =
    1.24              context.get(DiagnosticListener.class);
    1.25          this.diagListener = diagListener;
    1.26 -
    1.27 -        Source source = Source.instance(context);
    1.28 -        this.enforceMandatoryWarnings = source.enforceMandatoryWarnings();
    1.29      }
    1.30      // where
    1.31          private int getIntOption(Options options, String optionName, int defaultValue) {
    1.32 @@ -473,10 +465,7 @@
    1.33       *  @param args   Fields of the warning message.
    1.34       */
    1.35      public void mandatoryWarning(DiagnosticPosition pos, String key, Object ... args) {
    1.36 -        if (enforceMandatoryWarnings)
    1.37 -            report(diags.mandatoryWarning(source, pos, key, args));
    1.38 -        else
    1.39 -            report(diags.warning(source, pos, key, args));
    1.40 +        report(diags.mandatoryWarning(source, pos, key, args));
    1.41      }
    1.42  
    1.43      /** Report a warning that cannot be suppressed.
    1.44 @@ -514,34 +503,43 @@
    1.45      }
    1.46  
    1.47      /** Provide a non-fatal notification, unless suppressed by the -nowarn option.
    1.48 +     *  @param file   The file to which the note applies.
    1.49 +     *  @param key    The key for the localized notification message.
    1.50 +     *  @param args   Fields of the notification message.
    1.51 +     */
    1.52 +    public void note(JavaFileObject file, String key, Object ... args) {
    1.53 +        report(diags.note(wrap(file), null, key, args));
    1.54 +    }
    1.55 +
    1.56 +    /** Provide a non-fatal notification, unless suppressed by the -nowarn option.
    1.57       *  @param key    The key for the localized notification message.
    1.58       *  @param args   Fields of the notification message.
    1.59       */
    1.60      public void mandatoryNote(final JavaFileObject file, String key, Object ... args) {
    1.61 -        JCDiagnostic.DiagnosticSource wrapper = null;
    1.62 -        if (file != null) {
    1.63 -            wrapper = new JCDiagnostic.DiagnosticSource() {
    1.64 -                    public JavaFileObject getFile() {
    1.65 -                        return file;
    1.66 -                    }
    1.67 -                    public CharSequence getName() {
    1.68 -                        return JavacFileManager.getJavacBaseFileName(getFile());
    1.69 -                    }
    1.70 -                    public int getLineNumber(int pos) {
    1.71 -                        return Log.this.getLineNumber(pos);
    1.72 -                    }
    1.73 -                    public int getColumnNumber(int pos) {
    1.74 -                        return Log.this.getColumnNumber(pos);
    1.75 -                    }
    1.76 -                    public Map<JCTree, Integer> getEndPosTable() {
    1.77 -                        return (endPosTables == null ? null : endPosTables.get(file));
    1.78 -                    }
    1.79 -                };
    1.80 +        report(diags.mandatoryNote(wrap(file), key, args));
    1.81 +    }
    1.82 +
    1.83 +    private JCDiagnostic.DiagnosticSource wrap(final JavaFileObject file) {
    1.84 +        if (file == null) {
    1.85 +            return null;
    1.86          }
    1.87 -        if (enforceMandatoryWarnings)
    1.88 -            report(diags.mandatoryNote(wrapper, key, args));
    1.89 -        else
    1.90 -            report(diags.note(wrapper, null, key, args));
    1.91 +        return new JCDiagnostic.DiagnosticSource() {
    1.92 +            public JavaFileObject getFile() {
    1.93 +                return file;
    1.94 +            }
    1.95 +            public CharSequence getName() {
    1.96 +                return JavacFileManager.getJavacBaseFileName(getFile());
    1.97 +            }
    1.98 +            public int getLineNumber(int pos) {
    1.99 +                return Log.this.getLineNumber(pos);
   1.100 +            }
   1.101 +            public int getColumnNumber(int pos) {
   1.102 +                return Log.this.getColumnNumber(pos);
   1.103 +            }
   1.104 +            public Map<JCTree, Integer> getEndPosTable() {
   1.105 +                return (endPosTables == null ? null : endPosTables.get(file));
   1.106 +            }
   1.107 +        };
   1.108      }
   1.109  
   1.110      private DiagnosticPosition wrap(int pos) {

mercurial