changeset 2371:991f11e13598

8006346: doclint should make allowance for headers generated by standard doclet Reviewed-by: mcimadamore
author jjg
date Thu, 28 Mar 2013 10:49:39 -0700
parents a200d8ccfe47
children d3648557391b
files src/share/classes/com/sun/tools/doclint/Checker.java src/share/classes/com/sun/tools/doclint/DocLint.java src/share/classes/com/sun/tools/doclint/Env.java src/share/classes/com/sun/tools/javac/main/Main.java src/share/classes/com/sun/tools/javadoc/DocEnv.java test/tools/javac/doclint/ImplicitHeadersTest.java test/tools/javadoc/doclint/ImplicitHeadersTest.java
diffstat 7 files changed, 102 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/com/sun/tools/doclint/Checker.java	Thu Mar 28 11:39:04 2013 +0000
+++ b/src/share/classes/com/sun/tools/doclint/Checker.java	Thu Mar 28 10:49:39 2013 -0700
@@ -122,12 +122,15 @@
     private Deque<TagStackItem> tagStack; // TODO: maybe want to record starting tree as well
     private HtmlTag currHeaderTag;
 
+    private final int implicitHeaderLevel;
+
     // <editor-fold defaultstate="collapsed" desc="Top level">
 
     Checker(Env env) {
         env.getClass();
         this.env = env;
         tagStack = new LinkedList<TagStackItem>();
+        implicitHeaderLevel = env.implicitHeaderLevel;
     }
 
     public Void scan(DocCommentTree tree, TreePath p) {
@@ -386,7 +389,7 @@
 
     private int getHeaderLevel(HtmlTag tag) {
         if (tag == null)
-            return 0;
+            return implicitHeaderLevel;
         switch (tag) {
             case H1: return 1;
             case H2: return 2;
--- a/src/share/classes/com/sun/tools/doclint/DocLint.java	Thu Mar 28 11:39:04 2013 +0000
+++ b/src/share/classes/com/sun/tools/doclint/DocLint.java	Thu Mar 28 10:49:39 2013 -0700
@@ -30,6 +30,7 @@
 import java.io.PrintWriter;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.regex.Pattern;
 
 import javax.lang.model.element.Name;
 import javax.tools.StandardLocation;
@@ -72,6 +73,7 @@
     public static final String XMSGS_OPTION = "-Xmsgs";
     public static final String XMSGS_CUSTOM_PREFIX = "-Xmsgs:";
     private static final String STATS = "-stats";
+    public static final String XIMPLICIT_HEADERS = "-XimplicitHeaders:";
 
     // <editor-fold defaultstate="collapsed" desc="Command-line entry point">
     public static void main(String... args) {
@@ -289,6 +291,9 @@
                 env.messages.setOptions(null);
             } else if (arg.startsWith(XMSGS_CUSTOM_PREFIX)) {
                 env.messages.setOptions(arg.substring(arg.indexOf(":") + 1));
+            } else if (arg.matches(XIMPLICIT_HEADERS + "[1-6]")) {
+                char ch = arg.charAt(arg.length() - 1);
+                env.setImplicitHeaders(Character.digit(ch, 10));
             } else
                 throw new IllegalArgumentException(arg);
         }
--- a/src/share/classes/com/sun/tools/doclint/Env.java	Thu Mar 28 11:39:04 2013 +0000
+++ b/src/share/classes/com/sun/tools/doclint/Env.java	Thu Mar 28 10:49:39 2013 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2013, Oracle and/or its affiliates. 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
@@ -83,6 +83,8 @@
     /** Message handler. */
     final Messages messages;
 
+    int implicitHeaderLevel = 0;
+
     // Utility classes
     DocTrees trees;
     Elements elements;
@@ -102,7 +104,7 @@
     DocCommentTree currDocComment;
     /**
      * The access kind of the declaration containing the comment currently being analyzed.
-     * This is the minimum (most restrictive) access kind of the declaration iteself
+     * This is the minimum (most restrictive) access kind of the declaration itself
      * and that of its containers. For example, a public method in a private class is
      * noted as private.
      */
@@ -128,6 +130,10 @@
         java_lang_Void = elements.getTypeElement("java.lang.Void").asType();
     }
 
+    void setImplicitHeaders(int n) {
+        implicitHeaderLevel = n;
+    }
+
     /** Set the current declaration and its doc comment. */
     void setCurrent(TreePath path, DocCommentTree comment) {
         currPath = path;
--- a/src/share/classes/com/sun/tools/javac/main/Main.java	Thu Mar 28 11:39:04 2013 +0000
+++ b/src/share/classes/com/sun/tools/javac/main/Main.java	Thu Mar 28 10:49:39 2013 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2013, Oracle and/or its affiliates. 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
@@ -497,6 +497,8 @@
                 if (!(doclintOpts.size() == 1
                         && doclintOpts.iterator().next().equals(DocLint.XMSGS_CUSTOM_PREFIX + "none"))) {
                     JavacTask t = BasicJavacTask.instance(context);
+                    // standard doclet normally generates H1, H2
+                    doclintOpts.add(DocLint.XIMPLICIT_HEADERS + "2");
                     new DocLint().init(t, doclintOpts.toArray(new String[doclintOpts.size()]));
                     comp.keepComments = true;
                 }
--- a/src/share/classes/com/sun/tools/javadoc/DocEnv.java	Thu Mar 28 11:39:04 2013 +0000
+++ b/src/share/classes/com/sun/tools/javadoc/DocEnv.java	Thu Mar 28 10:49:39 2013 -0700
@@ -810,6 +810,8 @@
 
         JavacTask t = BasicJavacTask.instance(context);
         doclint = new DocLint();
+        // standard doclet normally generates H1, H2
+        doclintOpts.add(DocLint.XIMPLICIT_HEADERS + "2");
         doclint.init(t, doclintOpts.toArray(new String[doclintOpts.size()]), false);
     }
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/doclint/ImplicitHeadersTest.java	Thu Mar 28 10:49:39 2013 -0700
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2013, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 8006346
+ * @summary doclint should make allowance for headers generated by standard doclet
+ * @compile -Xdoclint:all/public ImplicitHeadersTest.java
+ */
+
+/**
+ * <h3> Header </h3>
+ */
+public class ImplicitHeadersTest { }
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javadoc/doclint/ImplicitHeadersTest.java	Thu Mar 28 10:49:39 2013 -0700
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2013, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 8006346
+ * @summary doclint should make allowance for headers generated by standard doclet
+ */
+
+import java.io.File;
+
+/**
+ * <h3> Header </h3>
+ */
+public class ImplicitHeadersTest {
+    public static void main(String... args) {
+        File testSrc = new File(System.getProperty("test.src"));
+        File testFile = new File(testSrc, ImplicitHeadersTest.class.getSimpleName() + ".java");
+        String[] javadocArgs = { "-d", "out", testFile.getPath() };
+        int rc = com.sun.tools.javadoc.Main.execute(javadocArgs);
+        if (rc != 0)
+            throw new Error("unexpected exit: rc=" + rc);
+    }
+}
+