8004891: Check for abstract method in javadoc does not conform to the language model
authorbpatel
Fri, 04 Jan 2013 23:06:05 -0800
changeset 15034 b7c791bc4526
parent 15033 acc6a1f8bd37
child 15035 d03c311f44e6
8004891: Check for abstract method in javadoc does not conform to the language model Reviewed-by: jjg
langtools/src/share/classes/com/sun/tools/doclets/formats/html/AbstractMemberWriter.java
langtools/src/share/classes/com/sun/tools/javadoc/MethodDocImpl.java
langtools/test/com/sun/javadoc/testAbstractMethod/TestAbstractMethod.java
langtools/test/com/sun/javadoc/testAbstractMethod/pkg/A.java
langtools/test/com/sun/javadoc/testAbstractMethod/pkg/B.java
langtools/test/com/sun/javadoc/testAbstractMethod/pkg/C.java
--- a/langtools/src/share/classes/com/sun/tools/doclets/formats/html/AbstractMemberWriter.java	Tue Jan 01 17:50:29 2013 -0800
+++ b/langtools/src/share/classes/com/sun/tools/doclets/formats/html/AbstractMemberWriter.java	Fri Jan 04 23:06:05 2013 -0800
@@ -321,7 +321,8 @@
             code.addContent(" ");
         }
         if (member.isMethod()) {
-            if (((MethodDoc)member).isAbstract()) {
+            if (!(member.containingClass().isInterface()) &&
+                    ((MethodDoc)member).isAbstract()) {
                 code.addContent("abstract ");
             }
             // This check for isDefault() and the default modifier needs to be
@@ -329,7 +330,7 @@
             // method summary section. Once the default modifier is added
             // to the Modifier list on DocEnv and once it is updated to use the
             // javax.lang.model.element.Modifier, we will need to remove this.
-            else if (((MethodDoc)member).isDefault()) {
+            if (((MethodDoc)member).isDefault()) {
                 code.addContent("default ");
             }
         }
@@ -561,11 +562,14 @@
         if (member instanceof MethodDoc && !member.isAnnotationTypeElement()) {
             int methodType = (member.isStatic()) ? MethodTypes.STATIC.value() :
                     MethodTypes.INSTANCE.value();
-            methodType = (classdoc.isInterface() || ((MethodDoc)member).isAbstract()) ?
-                    methodType | MethodTypes.ABSTRACT.value() :
-                    methodType | MethodTypes.CONCRETE.value();
-            if (((MethodDoc)member).isDefault()) {
-                methodType = methodType | MethodTypes.DEFAULT.value();
+            if (member.containingClass().isInterface()) {
+                methodType = (((MethodDoc) member).isAbstract())
+                        ? methodType | MethodTypes.ABSTRACT.value()
+                        : methodType | MethodTypes.DEFAULT.value();
+            } else {
+                methodType = (((MethodDoc) member).isAbstract())
+                        ? methodType | MethodTypes.ABSTRACT.value()
+                        : methodType | MethodTypes.CONCRETE.value();
             }
             if (Util.isDeprecated(member) || Util.isDeprecated(classdoc)) {
                 methodType = methodType | MethodTypes.DEPRECATED.value();
--- a/langtools/src/share/classes/com/sun/tools/javadoc/MethodDocImpl.java	Tue Jan 01 17:50:29 2013 -0800
+++ b/langtools/src/share/classes/com/sun/tools/javadoc/MethodDocImpl.java	Fri Jan 04 23:06:05 2013 -0800
@@ -86,16 +86,7 @@
      * Return true if this method is abstract
      */
     public boolean isAbstract() {
-        //### This is dubious, but old 'javadoc' apparently does it.
-        //### I regard this as a bug and an obstacle to treating the
-        //### doclet API as a proper compile-time reflection facility.
-        //### (maddox 09/26/2000)
-        if (containingClass().isInterface()) {
-            //### Don't force creation of ClassDocImpl for super here.
-            // Abstract modifier is implicit.  Strip/canonicalize it.
-            return false;
-        }
-        return Modifier.isAbstract(getModifiers());
+        return (Modifier.isAbstract(getModifiers()) && !isDefault());
     }
 
     /**
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/com/sun/javadoc/testAbstractMethod/TestAbstractMethod.java	Fri Jan 04 23:06:05 2013 -0800
@@ -0,0 +1,121 @@
+/*
+ * Copyright (c) 2012, 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      8004891
+ * @summary  Make sure that the abstract method is identified correctly
+ *           if the abstract modifier is present explicitly or implicitly.
+ * @author   bpatel
+ * @library  ../lib/
+ * @build    JavadocTester TestAbstractMethod
+ * @run main TestAbstractMethod
+ */
+
+public class TestAbstractMethod extends JavadocTester {
+
+    //Test information.
+    private static final String BUG_ID = "8004891";
+
+    //Javadoc arguments.
+    private static final String[] ARGS = new String[] {
+        "-d", BUG_ID, "-sourcepath", SRC_DIR, "pkg"
+    };
+
+    //Input for string search tests.
+    private static final String[][] TEST = {
+        {BUG_ID + FS + "pkg" + FS + "A.html",
+            "<td class=\"colFirst\"><code>default void</code></td>"},
+        {BUG_ID + FS + "pkg" + FS + "A.html",
+            "<caption><span id=\"t0\" class=\"activeTableTab\"><span>" +
+            "All Methods</span><span class=\"tabEnd\">&nbsp;</span></span>" +
+            "<span id=\"t2\" class=\"tableTab\"><span>" +
+            "<a href=\"javascript:show(2);\">Instance Methods</a></span>" +
+            "<span class=\"tabEnd\">&nbsp;</span></span><span id=\"t3\" " +
+            "class=\"tableTab\"><span><a href=\"javascript:show(4);\">" +
+            "Abstract Methods</a></span><span class=\"tabEnd\">&nbsp;</span>" +
+            "</span><span id=\"t5\" class=\"tableTab\"><span>" +
+            "<a href=\"javascript:show(16);\">Default Methods</a></span>" +
+            "<span class=\"tabEnd\">&nbsp;</span></span></caption>"},
+        {BUG_ID + FS + "pkg" + FS + "B.html",
+            "<caption><span id=\"t0\" class=\"activeTableTab\"><span>" +
+            "All Methods</span><span class=\"tabEnd\">&nbsp;</span></span>" +
+            "<span id=\"t2\" class=\"tableTab\"><span>" +
+            "<a href=\"javascript:show(2);\">Instance Methods</a></span>" +
+            "<span class=\"tabEnd\">&nbsp;</span></span><span id=\"t3\" " +
+            "class=\"tableTab\"><span><a href=\"javascript:show(4);\">Abstract " +
+            "Methods</a></span><span class=\"tabEnd\">&nbsp;</span></span>" +
+            "<span id=\"t4\" class=\"tableTab\"><span>" +
+            "<a href=\"javascript:show(8);\">Concrete Methods</a></span>" +
+            "<span class=\"tabEnd\">&nbsp;</span></span></caption>"},
+        {BUG_ID + FS + "pkg" + FS + "B.html",
+            "<td class=\"colFirst\"><code>abstract void</code></td>"},
+        {BUG_ID + FS + "pkg" + FS + "C.html",
+            "<caption><span id=\"t0\" class=\"activeTableTab\"><span>" +
+            "All Methods</span><span class=\"tabEnd\">&nbsp;</span></span>" +
+            "<span id=\"t2\" class=\"tableTab\"><span>" +
+            "<a href=\"javascript:show(2);\">Instance Methods</a></span>" +
+            "<span class=\"tabEnd\">&nbsp;</span></span>" +
+            "<span id=\"t5\" class=\"tableTab\"><span>" +
+            "<a href=\"javascript:show(16);\">Default Methods</a></span>" +
+            "<span class=\"tabEnd\">&nbsp;</span></span></caption>"},
+        {BUG_ID + FS + "pkg" + FS + "C.html",
+            "<td class=\"colFirst\"><code>default void</code></td>"}
+    };
+    private static final String[][] NEGATED_TEST = {
+        {BUG_ID + FS + "pkg" + FS + "A.html",
+            "<td class=\"colFirst\"><code>abstract void</code></td>"},
+        {BUG_ID + FS + "pkg" + FS + "B.html",
+            "<span><a href=\"javascript:show(16);\">Default Methods</a></span>" +
+            "<span class=\"tabEnd\">&nbsp;</span>"},
+        {BUG_ID + FS + "pkg" + FS + "B.html",
+            "<td class=\"colFirst\"><code>default void</code></td>"},
+        {BUG_ID + FS + "pkg" + FS + "C.html",
+            "<span><a href=\"javascript:show(4);\">Abstract Methods</a></span>" +
+            "<span class=\"tabEnd\">&nbsp;</span>"}
+    };
+
+    /**
+     * The entry point of the test.
+     * @param args the array of command line arguments.
+     */
+    public static void main(String[] args) {
+        TestAbstractMethod tester = new TestAbstractMethod();
+        run(tester, ARGS, TEST, NEGATED_TEST);
+        tester.printSummary();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public String getBugId() {
+        return BUG_ID;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public String getBugName() {
+        return getClass().getName();
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/com/sun/javadoc/testAbstractMethod/pkg/A.java	Fri Jan 04 23:06:05 2013 -0800
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2012, 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.
+ */
+
+package pkg;
+
+public interface A {
+
+    public void method1();
+
+    public default void defaultMethod() { }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/com/sun/javadoc/testAbstractMethod/pkg/B.java	Fri Jan 04 23:06:05 2013 -0800
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2012, 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.
+ */
+
+package pkg;
+
+public abstract class B {
+
+    public abstract void method1();
+
+    public void method2() { }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/com/sun/javadoc/testAbstractMethod/pkg/C.java	Fri Jan 04 23:06:05 2013 -0800
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2012, 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.
+ */
+
+package pkg;
+
+public interface C {
+
+    public default void onlyMethod() { }
+}