6507179: javadoc -source 1.3 does not work with jdk6

Wed, 25 Jun 2008 14:24:53 -0700

author
jjg
date
Wed, 25 Jun 2008 14:24:53 -0700
changeset 60
29d2485c1085
parent 59
4a3b9801f7a0
child 61
a0de486e86a1

6507179: javadoc -source 1.3 does not work with jdk6
Reviewed-by: mcimadamore

src/share/classes/com/sun/tools/javac/comp/Check.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/util/Log.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/util/MandatoryWarningHandler.java file | annotate | diff | comparison | revisions
test/tools/javadoc/sourceOption/SourceOption.java file | annotate | diff | comparison | revisions
test/tools/javadoc/sourceOption/p/A.java file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/classes/com/sun/tools/javac/comp/Check.java	Fri Jun 20 11:25:03 2008 +0100
     1.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Check.java	Wed Jun 25 14:24:53 2008 -0700
     1.3 @@ -100,9 +100,12 @@
     1.4  
     1.5          boolean verboseDeprecated = lint.isEnabled(LintCategory.DEPRECATION);
     1.6          boolean verboseUnchecked = lint.isEnabled(LintCategory.UNCHECKED);
     1.7 +        boolean enforceMandatoryWarnings = source.enforceMandatoryWarnings();
     1.8  
     1.9 -        deprecationHandler = new MandatoryWarningHandler(log,verboseDeprecated, "deprecated");
    1.10 -        uncheckedHandler = new MandatoryWarningHandler(log, verboseUnchecked, "unchecked");
    1.11 +        deprecationHandler = new MandatoryWarningHandler(log, verboseDeprecated,
    1.12 +                enforceMandatoryWarnings, "deprecated");
    1.13 +        uncheckedHandler = new MandatoryWarningHandler(log, verboseUnchecked,
    1.14 +                enforceMandatoryWarnings, "unchecked");
    1.15      }
    1.16  
    1.17      /** Switch: generics enabled?
     2.1 --- a/src/share/classes/com/sun/tools/javac/util/Log.java	Fri Jun 20 11:25:03 2008 +0100
     2.2 +++ b/src/share/classes/com/sun/tools/javac/util/Log.java	Wed Jun 25 14:24:53 2008 -0700
     2.3 @@ -34,7 +34,6 @@
     2.4  import javax.tools.DiagnosticListener;
     2.5  import javax.tools.JavaFileObject;
     2.6  
     2.7 -import com.sun.tools.javac.code.Source;
     2.8  import com.sun.tools.javac.file.JavacFileManager;
     2.9  import com.sun.tools.javac.tree.JCTree;
    2.10  import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
    2.11 @@ -86,10 +85,6 @@
    2.12       */
    2.13      public boolean emitWarnings;
    2.14  
    2.15 -    /** Enforce mandatory warnings.
    2.16 -     */
    2.17 -    private boolean enforceMandatoryWarnings;
    2.18 -
    2.19      /** Print stack trace on errors?
    2.20       */
    2.21      public boolean dumpOnError;
    2.22 @@ -138,9 +133,6 @@
    2.23          DiagnosticListener<? super JavaFileObject> diagListener =
    2.24              context.get(DiagnosticListener.class);
    2.25          this.diagListener = diagListener;
    2.26 -
    2.27 -        Source source = Source.instance(context);
    2.28 -        this.enforceMandatoryWarnings = source.enforceMandatoryWarnings();
    2.29      }
    2.30      // where
    2.31          private int getIntOption(Options options, String optionName, int defaultValue) {
    2.32 @@ -473,10 +465,7 @@
    2.33       *  @param args   Fields of the warning message.
    2.34       */
    2.35      public void mandatoryWarning(DiagnosticPosition pos, String key, Object ... args) {
    2.36 -        if (enforceMandatoryWarnings)
    2.37 -            report(diags.mandatoryWarning(source, pos, key, args));
    2.38 -        else
    2.39 -            report(diags.warning(source, pos, key, args));
    2.40 +        report(diags.mandatoryWarning(source, pos, key, args));
    2.41      }
    2.42  
    2.43      /** Report a warning that cannot be suppressed.
    2.44 @@ -514,34 +503,43 @@
    2.45      }
    2.46  
    2.47      /** Provide a non-fatal notification, unless suppressed by the -nowarn option.
    2.48 +     *  @param file   The file to which the note applies.
    2.49 +     *  @param key    The key for the localized notification message.
    2.50 +     *  @param args   Fields of the notification message.
    2.51 +     */
    2.52 +    public void note(JavaFileObject file, String key, Object ... args) {
    2.53 +        report(diags.note(wrap(file), null, key, args));
    2.54 +    }
    2.55 +
    2.56 +    /** Provide a non-fatal notification, unless suppressed by the -nowarn option.
    2.57       *  @param key    The key for the localized notification message.
    2.58       *  @param args   Fields of the notification message.
    2.59       */
    2.60      public void mandatoryNote(final JavaFileObject file, String key, Object ... args) {
    2.61 -        JCDiagnostic.DiagnosticSource wrapper = null;
    2.62 -        if (file != null) {
    2.63 -            wrapper = new JCDiagnostic.DiagnosticSource() {
    2.64 -                    public JavaFileObject getFile() {
    2.65 -                        return file;
    2.66 -                    }
    2.67 -                    public CharSequence getName() {
    2.68 -                        return JavacFileManager.getJavacBaseFileName(getFile());
    2.69 -                    }
    2.70 -                    public int getLineNumber(int pos) {
    2.71 -                        return Log.this.getLineNumber(pos);
    2.72 -                    }
    2.73 -                    public int getColumnNumber(int pos) {
    2.74 -                        return Log.this.getColumnNumber(pos);
    2.75 -                    }
    2.76 -                    public Map<JCTree, Integer> getEndPosTable() {
    2.77 -                        return (endPosTables == null ? null : endPosTables.get(file));
    2.78 -                    }
    2.79 -                };
    2.80 +        report(diags.mandatoryNote(wrap(file), key, args));
    2.81 +    }
    2.82 +
    2.83 +    private JCDiagnostic.DiagnosticSource wrap(final JavaFileObject file) {
    2.84 +        if (file == null) {
    2.85 +            return null;
    2.86          }
    2.87 -        if (enforceMandatoryWarnings)
    2.88 -            report(diags.mandatoryNote(wrapper, key, args));
    2.89 -        else
    2.90 -            report(diags.note(wrapper, null, key, args));
    2.91 +        return new JCDiagnostic.DiagnosticSource() {
    2.92 +            public JavaFileObject getFile() {
    2.93 +                return file;
    2.94 +            }
    2.95 +            public CharSequence getName() {
    2.96 +                return JavacFileManager.getJavacBaseFileName(getFile());
    2.97 +            }
    2.98 +            public int getLineNumber(int pos) {
    2.99 +                return Log.this.getLineNumber(pos);
   2.100 +            }
   2.101 +            public int getColumnNumber(int pos) {
   2.102 +                return Log.this.getColumnNumber(pos);
   2.103 +            }
   2.104 +            public Map<JCTree, Integer> getEndPosTable() {
   2.105 +                return (endPosTables == null ? null : endPosTables.get(file));
   2.106 +            }
   2.107 +        };
   2.108      }
   2.109  
   2.110      private DiagnosticPosition wrap(int pos) {
     3.1 --- a/src/share/classes/com/sun/tools/javac/util/MandatoryWarningHandler.java	Fri Jun 20 11:25:03 2008 +0100
     3.2 +++ b/src/share/classes/com/sun/tools/javac/util/MandatoryWarningHandler.java	Wed Jun 25 14:24:53 2008 -0700
     3.3 @@ -101,13 +101,17 @@
     3.4       *                individual instances should be given, or whether an aggregate
     3.5       *                message should be generated at the end of the compilation.
     3.6       *                Typically set via  -Xlint:option.
     3.7 +     * @param enforceMandatory
     3.8 +     *                True if mandatory warnings and notes are being enforced.
     3.9       * @param prefix  A common prefix for the set of message keys for
    3.10       *                the messages that may be generated.
    3.11       */
    3.12 -    public MandatoryWarningHandler(Log log, boolean verbose, String prefix) {
    3.13 +    public MandatoryWarningHandler(Log log, boolean verbose,
    3.14 +                                   boolean enforceMandatory, String prefix) {
    3.15          this.log = log;
    3.16          this.verbose = verbose;
    3.17          this.prefix = prefix;
    3.18 +        this.enforceMandatory = enforceMandatory;
    3.19      }
    3.20  
    3.21      /**
    3.22 @@ -122,7 +126,7 @@
    3.23  
    3.24              if (log.nwarnings < log.MaxWarnings) {
    3.25                  // generate message and remember the source file
    3.26 -                log.mandatoryWarning(pos, msg, args);
    3.27 +                logMandatoryWarning(pos, msg, args);
    3.28                  sourcesWithReportedWarnings.add(currentSource);
    3.29              } else if (deferredDiagnosticKind == null) {
    3.30                  // set up deferred message
    3.31 @@ -163,12 +167,12 @@
    3.32      public void reportDeferredDiagnostic() {
    3.33          if (deferredDiagnosticKind != null) {
    3.34              if (deferredDiagnosticArg == null)
    3.35 -                log.mandatoryNote(deferredDiagnosticSource, deferredDiagnosticKind.getKey(prefix));
    3.36 +                logMandatoryNote(deferredDiagnosticSource, deferredDiagnosticKind.getKey(prefix));
    3.37              else
    3.38 -                log.mandatoryNote(deferredDiagnosticSource, deferredDiagnosticKind.getKey(prefix), deferredDiagnosticArg);
    3.39 +                logMandatoryNote(deferredDiagnosticSource, deferredDiagnosticKind.getKey(prefix), deferredDiagnosticArg);
    3.40  
    3.41              if (!verbose)
    3.42 -                log.mandatoryNote(deferredDiagnosticSource, prefix + ".recompile");
    3.43 +                logMandatoryNote(deferredDiagnosticSource, prefix + ".recompile");
    3.44          }
    3.45      }
    3.46  
    3.47 @@ -224,4 +228,32 @@
    3.48       * deferredDiagnosticKind is updated.
    3.49       */
    3.50      private Object deferredDiagnosticArg;
    3.51 +
    3.52 +    /**
    3.53 +     * True if mandatory warnings and notes are being enforced.
    3.54 +     */
    3.55 +    private final boolean enforceMandatory;
    3.56 +
    3.57 +    /**
    3.58 +     * Reports a mandatory warning to the log.  If mandatory warnings
    3.59 +     * are not being enforced, treat this as an ordinary warning.
    3.60 +     */
    3.61 +    private void logMandatoryWarning(DiagnosticPosition pos, String msg,
    3.62 +                                     Object... args) {
    3.63 +        if (enforceMandatory)
    3.64 +            log.mandatoryWarning(pos, msg, args);
    3.65 +        else
    3.66 +            log.warning(pos, msg, args);
    3.67 +    }
    3.68 +
    3.69 +    /**
    3.70 +     * Reports a mandatory note to the log.  If mandatory notes are
    3.71 +     * not being enforced, treat this as an ordinary note.
    3.72 +     */
    3.73 +    private void logMandatoryNote(JavaFileObject file, String msg, Object... args) {
    3.74 +        if (enforceMandatory)
    3.75 +            log.mandatoryNote(file, msg, args);
    3.76 +        else
    3.77 +            log.note(file, msg, args);
    3.78 +    }
    3.79  }
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/test/tools/javadoc/sourceOption/SourceOption.java	Wed Jun 25 14:24:53 2008 -0700
     4.3 @@ -0,0 +1,47 @@
     4.4 +/*
     4.5 + * Copyright 2006 Sun Microsystems, Inc.  All Rights Reserved.
     4.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4.7 + *
     4.8 + * This code is free software; you can redistribute it and/or modify it
     4.9 + * under the terms of the GNU General Public License version 2 only, as
    4.10 + * published by the Free Software Foundation.
    4.11 + *
    4.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    4.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    4.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    4.15 + * version 2 for more details (a copy is included in the LICENSE file that
    4.16 + * accompanied this code).
    4.17 + *
    4.18 + * You should have received a copy of the GNU General Public License version
    4.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    4.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    4.21 + *
    4.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    4.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
    4.24 + * have any questions.
    4.25 + */
    4.26 +
    4.27 +/*
    4.28 + * @test
    4.29 + * @bug     6507179
    4.30 + * @summary Ensure that "-source" option isn't ignored.
    4.31 + * @author  Scott Seligman
    4.32 + */
    4.33 +
    4.34 +import com.sun.javadoc.*;
    4.35 +
    4.36 +public class SourceOption extends Doclet {
    4.37 +
    4.38 +    public static void main(String[] args) {
    4.39 +        if (com.sun.tools.javadoc.Main.execute(
    4.40 +                "javadoc",
    4.41 +                "SourceOption",
    4.42 +                new String[] {"-source", "1.3", "p"}) != 0)
    4.43 +            throw new Error("Javadoc encountered warnings or errors.");
    4.44 +    }
    4.45 +
    4.46 +    public static boolean start(RootDoc root) {
    4.47 +        root.classes();         // force parser into action
    4.48 +        return true;
    4.49 +    }
    4.50 +}
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/test/tools/javadoc/sourceOption/p/A.java	Wed Jun 25 14:24:53 2008 -0700
     5.3 @@ -0,0 +1,29 @@
     5.4 +/*
     5.5 + * Copyright 2004 Sun Microsystems, Inc.  All Rights Reserved.
     5.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     5.7 + *
     5.8 + * This code is free software; you can redistribute it and/or modify it
     5.9 + * under the terms of the GNU General Public License version 2 only, as
    5.10 + * published by the Free Software Foundation.
    5.11 + *
    5.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    5.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    5.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    5.15 + * version 2 for more details (a copy is included in the LICENSE file that
    5.16 + * accompanied this code).
    5.17 + *
    5.18 + * You should have received a copy of the GNU General Public License version
    5.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    5.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    5.21 + *
    5.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    5.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
    5.24 + * have any questions.
    5.25 + */
    5.26 +
    5.27 +package p;
    5.28 +
    5.29 +public class A {
    5.30 +    boolean assert;     // illegal since 1.4
    5.31 +    boolean enum;       // illegal since 5
    5.32 +}

mercurial