8191030: @value Tags are not resolved by javadoc 9.
authorksrini
Thu, 07 Dec 2017 14:15:14 -0800
changeset 48213 59696a3595bd
parent 48212 6a8ab8d1fb8b
child 48214 c3bf1ae9c51d
8191030: @value Tags are not resolved by javadoc 9. Reviewed-by: jjg
src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/taglets/ValueTaglet.java
src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/Utils.java
test/langtools/jdk/javadoc/doclet/testDeprecatedDocs/TestDeprecatedDocs.java
test/langtools/jdk/javadoc/doclet/testValueTag/TestValueTag.java
test/langtools/jdk/javadoc/doclet/testValueTag/pkg3/RT.java
--- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/taglets/ValueTaglet.java	Thu Dec 07 22:37:45 2017 +0100
+++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/taglets/ValueTaglet.java	Thu Dec 07 14:15:14 2017 -0800
@@ -25,11 +25,8 @@
 
 package jdk.javadoc.internal.doclets.toolkit.taglets;
 
-
 import javax.lang.model.element.Element;
-import javax.lang.model.element.TypeElement;
 import javax.lang.model.element.VariableElement;
-import javax.lang.model.util.Elements;
 
 import com.sun.source.doctree.DocTree;
 import jdk.javadoc.internal.doclets.toolkit.BaseConfiguration;
@@ -121,60 +118,26 @@
     }
 
     /**
-     * Given the name of the field, return the corresponding VariableElement. Return null
-     * due to invalid use of value tag if the name is null or empty string and if
-     * the value tag is not used on a field.
+     * Returns the referenced field or a null if the value tag
+     * is empty or the reference is invalid.
      *
-     * @param holder the element holding the tag
-     * @param config the current configuration of the doclet.
+     * @param holder the tag holder.
+     * @param config the  configuration of the doclet.
      * @param tag the value tag.
      *
-     * @return the corresponding VariableElement. If the name is null or empty string,
-     * return field that the value tag was used in. Return null if the name is null
-     * or empty string and if the value tag is not used on a field.
+     * @return the referenced field or null.
      */
     private VariableElement getVariableElement(Element holder, BaseConfiguration config, DocTree tag) {
-        Utils utils = config.utils;
-        CommentHelper ch = utils.getCommentHelper(holder);
+        CommentHelper ch = config.utils.getCommentHelper(holder);
         String signature = ch.getReferencedSignature(tag);
 
-        if (signature == null) { // no reference
-            //Base case: no label.
-            if (utils.isVariableElement(holder)) {
-                return (VariableElement)(holder);
-            } else {
-                // If the value tag does not specify a parameter which is a valid field and
-                // it is not used within the comments of a valid field, return null.
-                 return null;
-            }
-        }
+        Element e = signature == null
+                ? holder
+                : ch.getReferencedMember(config, tag);
 
-        String[] sigValues = signature.split("#");
-        String memberName = null;
-        TypeElement te = null;
-        if (sigValues.length == 1) {
-            //Case 2:  @value in same class.
-            if (utils.isExecutableElement(holder) || utils.isVariableElement(holder)) {
-                te = utils.getEnclosingTypeElement(holder);
-            } else if (utils.isTypeElement(holder)) {
-                te = utils.getTopMostContainingTypeElement(holder);
-            }
-            memberName = sigValues[0];
-        } else {
-            //Case 3: @value in different class.
-            Elements elements = config.docEnv.getElementUtils();
-            te = elements.getTypeElement(sigValues[0]);
-            memberName = sigValues[1];
-        }
-        if (te == null) {
-            return null;
-        }
-        for (Element field : utils.getFields(te)) {
-            if (utils.getSimpleName(field).equals(memberName)) {
-                return (VariableElement)field;
-            }
-        }
-        return null;
+        return (e != null && config.utils.isVariableElement(e))
+                ? (VariableElement) e
+                : null;
     }
 
     /**
--- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/Utils.java	Thu Dec 07 22:37:45 2017 +0100
+++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/Utils.java	Thu Dec 07 14:15:14 2017 -0800
@@ -2365,9 +2365,6 @@
 
     List<Element> getItems(Element e, boolean filter, ElementKind select) {
         List<Element> elements = new ArrayList<>();
-        // maintain backward compatibility by returning a null list, see AnnotationDocType.methods().
-        if (configuration.backwardCompatibility && e.getKind() == ANNOTATION_TYPE)
-            return elements;
         return new SimpleElementVisitor9<List<Element>, Void>() {
 
             @Override
--- a/test/langtools/jdk/javadoc/doclet/testDeprecatedDocs/TestDeprecatedDocs.java	Thu Dec 07 22:37:45 2017 +0100
+++ b/test/langtools/jdk/javadoc/doclet/testDeprecatedDocs/TestDeprecatedDocs.java	Thu Dec 07 14:15:14 2017 -0800
@@ -23,7 +23,8 @@
 
 /*
  * @test
- * @bug      4927552 8026567 8071982 8162674 8175200 8175218 8183511 8186332 8169819 8074407
+ * @bug      4927552 8026567 8071982 8162674 8175200 8175218 8183511 8186332
+ *           8169819 8074407 8191030
  * @summary  test generated docs for deprecated items
  * @author   jamieh
  * @library  ../lib
@@ -257,24 +258,30 @@
                 + "<td class=\"colLast\"></td>\n"
                 + "</tr>\n"
                 + "<tr class=\"rowColor\">\n"
+                + "<th class=\"colDeprecatedItemName\" scope=\"row\"><a href=\"pkg/TestAnnotationType.html#field\">pkg.TestAnnotationType.field</a></th>\n"
+                + "<td class=\"colLast\">\n"
+                + "<div class=\"deprecationComment\">annotation_test4 passes.</div>\n"
+                + "</td>\n"
+                + "</tr>\n"
+                + "<tr class=\"altColor\">\n"
                 + "<th class=\"colDeprecatedItemName\" scope=\"row\"><a href=\"pkg/TestClass.html#field\">pkg.TestClass.field</a></th>\n"
                 + "<td class=\"colLast\">\n"
                 + "<div class=\"deprecationComment\">class_test2 passes. This is the second sentence of deprecated description for a field.</div>\n"
                 + "</td>\n"
                 + "</tr>\n"
-                + "<tr class=\"altColor\">\n"
+                + "<tr class=\"rowColor\">\n"
                 + "<th class=\"colDeprecatedItemName\" scope=\"row\"><a href=\"pkg/TestError.html#field\">pkg.TestError.field</a></th>\n"
                 + "<td class=\"colLast\">\n"
                 + "<div class=\"deprecationComment\">error_test2 passes.</div>\n"
                 + "</td>\n"
                 + "</tr>\n"
-                + "<tr class=\"rowColor\">\n"
+                + "<tr class=\"altColor\">\n"
                 + "<th class=\"colDeprecatedItemName\" scope=\"row\"><a href=\"pkg/TestException.html#field\">pkg.TestException.field</a></th>\n"
                 + "<td class=\"colLast\">\n"
                 + "<div class=\"deprecationComment\">exception_test2 passes.</div>\n"
                 + "</td>\n"
                 + "</tr>\n"
-                + "<tr class=\"altColor\">\n"
+                + "<tr class=\"rowColor\">\n"
                 + "<th class=\"colDeprecatedItemName\" scope=\"row\"><a href=\"pkg/TestInterface.html#field\">pkg.TestInterface.field</a></th>\n"
                 + "<td class=\"colLast\">\n"
                 + "<div class=\"deprecationComment\">interface_test2 passes.</div>\n"
--- a/test/langtools/jdk/javadoc/doclet/testValueTag/TestValueTag.java	Thu Dec 07 22:37:45 2017 +0100
+++ b/test/langtools/jdk/javadoc/doclet/testValueTag/TestValueTag.java	Thu Dec 07 14:15:14 2017 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2017, 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
@@ -23,9 +23,9 @@
 
 /*
  * @test
- * @bug      4764045 8004825 8026567
+ * @bug      4764045 8004825 8026567 8191030
  * @summary  This test ensures that the value tag works in all
- * use cases. The explainations for each test case are written below.
+ *           use cases, the tests are explained below.
  * @author   jamieh
  * @library ../lib
  * @modules jdk.javadoc/jdk.javadoc.internal.tool
@@ -103,7 +103,7 @@
         );
 
         checkOutput("pkg1/Class1.html", false,
-                //Base case:  using @value on a constant.
+                // Base case:  using @value on a constant.
                 "Result:  <a href=\"../pkg1/Class1.html#TEST_12_ERROR\">\"Test 12 "
                 + "generates an error message\"</a>");
 
@@ -119,23 +119,36 @@
                 "pkg1", "pkg2");
         checkExit(Exit.OK);
         checkOutput(Output.OUT, true,
-                //Test @value warning printed when used with non-constant.
+                // Test @value warning printed when used with non-constant.
                 "warning - @value tag (which references nonConstant) "
                 + "can only be used in constants.",
                 "warning - @value tag (which references NULL) "
                 + "can only be used in constants.",
                 "warning - @value tag (which references TEST_12_ERROR) "
-                + "can only be used in constants."
-// TODO: re-examine these.
-//                //Test warning printed for bad reference.
-//                "warning - UnknownClass#unknownConstant (referenced by "
-//                + "@value tag) is an unknown reference.",
-//                //Test warning printed for invalid use of @value.
-//                "warning - @value tag cannot be used here."
+                + "can only be used in constants.",
+                // Test warning printed for bad reference.
+                "warning - {@value UnknownClass#unknownConstant}"
+                + " (referenced by @value tag) is an unknown reference."
         );
         checkForException();
     }
 
+    @Test()
+    void test3() {
+        javadoc("-d", "out3",
+                "-sourcepath", testSrc,
+                "pkg2", "pkg3");
+        checkExit(Exit.OK);
+
+        checkOrder("pkg3/RT.html",
+                "The value is <a href=\"../pkg3/RT.html#CONSTANT\">\"constant\"</a>.",
+                "The value1 is <a href=\"../pkg3/RT.html#CONSTANT\">\"constant\"</a>.",
+                "The value2 is <a href=\"../pkg3/RT.html#CONSTANT\">\"constant\"</a>.",
+                "The value3 is <a href=\"../pkg2/Class3.html#TEST_12_PASSES\">"
+                + "\"Test 12 passes\"</a>.");
+    }
+
+
     void checkForException() {
         checkOutput(Output.STDERR, false, "DocletAbortException");
     }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/langtools/jdk/javadoc/doclet/testValueTag/pkg3/RT.java	Thu Dec 07 14:15:14 2017 -0800
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 2017, 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.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * 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 pkg3;
+
+public @interface RT {
+
+    /** The CONSTANT */
+    static String CONSTANT = "constant";
+    /**
+     *  The value is {@value CONSTANT}.
+     *  @return a value
+     */
+     int value();
+
+    /**
+     *  The value1 is {@value #CONSTANT}.
+     *  @return a value
+     */
+    int value1();
+
+    /**
+     *  The value2 is {@value pkg3.RT#CONSTANT}.
+     *  @return a value
+     */
+     int value2();
+
+    /**
+     *  The value3 is {@value pkg2.Class3#TEST_12_PASSES}.
+     *  @return a value
+     */
+    int value3();
+
+}