6507179: javadoc -source 1.3 does not work with jdk6
authorjjg
Wed, 25 Jun 2008 14:24:53 -0700
changeset 813 ab91293d33f4
parent 812 d60171f70ade
child 814 3d9921c0b40c
6507179: javadoc -source 1.3 does not work with jdk6 Reviewed-by: mcimadamore
langtools/src/share/classes/com/sun/tools/javac/comp/Check.java
langtools/src/share/classes/com/sun/tools/javac/util/Log.java
langtools/src/share/classes/com/sun/tools/javac/util/MandatoryWarningHandler.java
langtools/test/tools/javadoc/sourceOption/SourceOption.java
langtools/test/tools/javadoc/sourceOption/p/A.java
--- a/langtools/src/share/classes/com/sun/tools/javac/comp/Check.java	Fri Jun 20 11:25:03 2008 +0100
+++ b/langtools/src/share/classes/com/sun/tools/javac/comp/Check.java	Wed Jun 25 14:24:53 2008 -0700
@@ -100,9 +100,12 @@
 
         boolean verboseDeprecated = lint.isEnabled(LintCategory.DEPRECATION);
         boolean verboseUnchecked = lint.isEnabled(LintCategory.UNCHECKED);
+        boolean enforceMandatoryWarnings = source.enforceMandatoryWarnings();
 
-        deprecationHandler = new MandatoryWarningHandler(log,verboseDeprecated, "deprecated");
-        uncheckedHandler = new MandatoryWarningHandler(log, verboseUnchecked, "unchecked");
+        deprecationHandler = new MandatoryWarningHandler(log, verboseDeprecated,
+                enforceMandatoryWarnings, "deprecated");
+        uncheckedHandler = new MandatoryWarningHandler(log, verboseUnchecked,
+                enforceMandatoryWarnings, "unchecked");
     }
 
     /** Switch: generics enabled?
--- a/langtools/src/share/classes/com/sun/tools/javac/util/Log.java	Fri Jun 20 11:25:03 2008 +0100
+++ b/langtools/src/share/classes/com/sun/tools/javac/util/Log.java	Wed Jun 25 14:24:53 2008 -0700
@@ -34,7 +34,6 @@
 import javax.tools.DiagnosticListener;
 import javax.tools.JavaFileObject;
 
-import com.sun.tools.javac.code.Source;
 import com.sun.tools.javac.file.JavacFileManager;
 import com.sun.tools.javac.tree.JCTree;
 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
@@ -86,10 +85,6 @@
      */
     public boolean emitWarnings;
 
-    /** Enforce mandatory warnings.
-     */
-    private boolean enforceMandatoryWarnings;
-
     /** Print stack trace on errors?
      */
     public boolean dumpOnError;
@@ -138,9 +133,6 @@
         DiagnosticListener<? super JavaFileObject> diagListener =
             context.get(DiagnosticListener.class);
         this.diagListener = diagListener;
-
-        Source source = Source.instance(context);
-        this.enforceMandatoryWarnings = source.enforceMandatoryWarnings();
     }
     // where
         private int getIntOption(Options options, String optionName, int defaultValue) {
@@ -473,10 +465,7 @@
      *  @param args   Fields of the warning message.
      */
     public void mandatoryWarning(DiagnosticPosition pos, String key, Object ... args) {
-        if (enforceMandatoryWarnings)
-            report(diags.mandatoryWarning(source, pos, key, args));
-        else
-            report(diags.warning(source, pos, key, args));
+        report(diags.mandatoryWarning(source, pos, key, args));
     }
 
     /** Report a warning that cannot be suppressed.
@@ -514,34 +503,43 @@
     }
 
     /** Provide a non-fatal notification, unless suppressed by the -nowarn option.
+     *  @param file   The file to which the note applies.
+     *  @param key    The key for the localized notification message.
+     *  @param args   Fields of the notification message.
+     */
+    public void note(JavaFileObject file, String key, Object ... args) {
+        report(diags.note(wrap(file), null, key, args));
+    }
+
+    /** Provide a non-fatal notification, unless suppressed by the -nowarn option.
      *  @param key    The key for the localized notification message.
      *  @param args   Fields of the notification message.
      */
     public void mandatoryNote(final JavaFileObject file, String key, Object ... args) {
-        JCDiagnostic.DiagnosticSource wrapper = null;
-        if (file != null) {
-            wrapper = new JCDiagnostic.DiagnosticSource() {
-                    public JavaFileObject getFile() {
-                        return file;
-                    }
-                    public CharSequence getName() {
-                        return JavacFileManager.getJavacBaseFileName(getFile());
-                    }
-                    public int getLineNumber(int pos) {
-                        return Log.this.getLineNumber(pos);
-                    }
-                    public int getColumnNumber(int pos) {
-                        return Log.this.getColumnNumber(pos);
-                    }
-                    public Map<JCTree, Integer> getEndPosTable() {
-                        return (endPosTables == null ? null : endPosTables.get(file));
-                    }
-                };
+        report(diags.mandatoryNote(wrap(file), key, args));
+    }
+
+    private JCDiagnostic.DiagnosticSource wrap(final JavaFileObject file) {
+        if (file == null) {
+            return null;
         }
-        if (enforceMandatoryWarnings)
-            report(diags.mandatoryNote(wrapper, key, args));
-        else
-            report(diags.note(wrapper, null, key, args));
+        return new JCDiagnostic.DiagnosticSource() {
+            public JavaFileObject getFile() {
+                return file;
+            }
+            public CharSequence getName() {
+                return JavacFileManager.getJavacBaseFileName(getFile());
+            }
+            public int getLineNumber(int pos) {
+                return Log.this.getLineNumber(pos);
+            }
+            public int getColumnNumber(int pos) {
+                return Log.this.getColumnNumber(pos);
+            }
+            public Map<JCTree, Integer> getEndPosTable() {
+                return (endPosTables == null ? null : endPosTables.get(file));
+            }
+        };
     }
 
     private DiagnosticPosition wrap(int pos) {
--- a/langtools/src/share/classes/com/sun/tools/javac/util/MandatoryWarningHandler.java	Fri Jun 20 11:25:03 2008 +0100
+++ b/langtools/src/share/classes/com/sun/tools/javac/util/MandatoryWarningHandler.java	Wed Jun 25 14:24:53 2008 -0700
@@ -101,13 +101,17 @@
      *                individual instances should be given, or whether an aggregate
      *                message should be generated at the end of the compilation.
      *                Typically set via  -Xlint:option.
+     * @param enforceMandatory
+     *                True if mandatory warnings and notes are being enforced.
      * @param prefix  A common prefix for the set of message keys for
      *                the messages that may be generated.
      */
-    public MandatoryWarningHandler(Log log, boolean verbose, String prefix) {
+    public MandatoryWarningHandler(Log log, boolean verbose,
+                                   boolean enforceMandatory, String prefix) {
         this.log = log;
         this.verbose = verbose;
         this.prefix = prefix;
+        this.enforceMandatory = enforceMandatory;
     }
 
     /**
@@ -122,7 +126,7 @@
 
             if (log.nwarnings < log.MaxWarnings) {
                 // generate message and remember the source file
-                log.mandatoryWarning(pos, msg, args);
+                logMandatoryWarning(pos, msg, args);
                 sourcesWithReportedWarnings.add(currentSource);
             } else if (deferredDiagnosticKind == null) {
                 // set up deferred message
@@ -163,12 +167,12 @@
     public void reportDeferredDiagnostic() {
         if (deferredDiagnosticKind != null) {
             if (deferredDiagnosticArg == null)
-                log.mandatoryNote(deferredDiagnosticSource, deferredDiagnosticKind.getKey(prefix));
+                logMandatoryNote(deferredDiagnosticSource, deferredDiagnosticKind.getKey(prefix));
             else
-                log.mandatoryNote(deferredDiagnosticSource, deferredDiagnosticKind.getKey(prefix), deferredDiagnosticArg);
+                logMandatoryNote(deferredDiagnosticSource, deferredDiagnosticKind.getKey(prefix), deferredDiagnosticArg);
 
             if (!verbose)
-                log.mandatoryNote(deferredDiagnosticSource, prefix + ".recompile");
+                logMandatoryNote(deferredDiagnosticSource, prefix + ".recompile");
         }
     }
 
@@ -224,4 +228,32 @@
      * deferredDiagnosticKind is updated.
      */
     private Object deferredDiagnosticArg;
+
+    /**
+     * True if mandatory warnings and notes are being enforced.
+     */
+    private final boolean enforceMandatory;
+
+    /**
+     * Reports a mandatory warning to the log.  If mandatory warnings
+     * are not being enforced, treat this as an ordinary warning.
+     */
+    private void logMandatoryWarning(DiagnosticPosition pos, String msg,
+                                     Object... args) {
+        if (enforceMandatory)
+            log.mandatoryWarning(pos, msg, args);
+        else
+            log.warning(pos, msg, args);
+    }
+
+    /**
+     * Reports a mandatory note to the log.  If mandatory notes are
+     * not being enforced, treat this as an ordinary note.
+     */
+    private void logMandatoryNote(JavaFileObject file, String msg, Object... args) {
+        if (enforceMandatory)
+            log.mandatoryNote(file, msg, args);
+        else
+            log.note(file, msg, args);
+    }
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javadoc/sourceOption/SourceOption.java	Wed Jun 25 14:24:53 2008 -0700
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2006 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @bug     6507179
+ * @summary Ensure that "-source" option isn't ignored.
+ * @author  Scott Seligman
+ */
+
+import com.sun.javadoc.*;
+
+public class SourceOption extends Doclet {
+
+    public static void main(String[] args) {
+        if (com.sun.tools.javadoc.Main.execute(
+                "javadoc",
+                "SourceOption",
+                new String[] {"-source", "1.3", "p"}) != 0)
+            throw new Error("Javadoc encountered warnings or errors.");
+    }
+
+    public static boolean start(RootDoc root) {
+        root.classes();         // force parser into action
+        return true;
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javadoc/sourceOption/p/A.java	Wed Jun 25 14:24:53 2008 -0700
@@ -0,0 +1,29 @@
+/*
+ * Copyright 2004 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package p;
+
+public class A {
+    boolean assert;     // illegal since 1.4
+    boolean enum;       // illegal since 5
+}