[Patch] 8081820: Generate warnings for multiple «@param» and «@return»

Denis Istomin istomin.den at gmail.com
Tue Jan 10 01:29:33 UTC 2017


Hi,
Made patch for bug 8081820. Warnings are generated in doclint.

-- 
Denis Istomin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/javadoc-dev/attachments/20170110/035880ac/attachment.html>
-------------- next part --------------
# HG changeset patch
# User istomin
# Date 1480500213 -18000
#      Wed Nov 30 15:03:33 2016 +0500
# Node ID 82b8765d1a965fbd5dbe995273a6a37eb693c841
# Parent  d715163cd7c5e6edea8a566dbd76e70cf44a19e9
8081820: Generate warnings for multiple «@param» and «@return»

diff --git a/src/jdk.compiler/share/classes/com/sun/tools/doclint/Checker.java b/src/jdk.compiler/share/classes/com/sun/tools/doclint/Checker.java
--- a/src/jdk.compiler/share/classes/com/sun/tools/doclint/Checker.java
+++ b/src/jdk.compiler/share/classes/com/sun/tools/doclint/Checker.java
@@ -802,7 +802,11 @@
                     break;
             }
         } else {
-            foundParams.add(paramElement);
+            boolean unique = foundParams.add(paramElement);
+            
+            if (!unique) {
+                env.messages.warning(REFERENCE, tree, "dc.exists.param", nameTree);
+            }
         }
 
         warnIfEmpty(tree, tree.getDescription());
@@ -837,6 +841,10 @@
 
     @Override @DefinedBy(Api.COMPILER_TREE)
     public Void visitReturn(ReturnTree tree, Void ignore) {
+        if (foundReturn) {
+            env.messages.warning(REFERENCE, tree, "dc.exists.return"); 
+        }
+        
         Element e = env.trees.getElement(env.currPath);
         if (e.getKind() != ElementKind.METHOD
                 || ((ExecutableElement) e).getReturnType().getKind() == TypeKind.VOID)
diff --git a/src/jdk.compiler/share/classes/com/sun/tools/doclint/resources/doclint.properties b/src/jdk.compiler/share/classes/com/sun/tools/doclint/resources/doclint.properties
--- a/src/jdk.compiler/share/classes/com/sun/tools/doclint/resources/doclint.properties
+++ b/src/jdk.compiler/share/classes/com/sun/tools/doclint/resources/doclint.properties
@@ -39,6 +39,8 @@
 dc.empty = no description for @{0}
 dc.entity.invalid = invalid entity &{0};
 dc.exception.not.thrown = exception not thrown: {0}
+dc.exists.param = @param "{0}" has already been specified
+dc.exists.return = @return has already been specified
 dc.invalid.anchor = invalid name for anchor: "{0}"
 dc.invalid.param = invalid use of @param
 dc.invalid.return = invalid use of @return
diff --git a/test/tools/doclint/DuplicateParamTest.java b/test/tools/doclint/DuplicateParamTest.java
new file mode 100644
--- /dev/null
+++ b/test/tools/doclint/DuplicateParamTest.java
@@ -0,0 +1,23 @@
+/*
+ * @test /nodynamiccopyright/
+ * @bug 8081820
+ * @summary Validate parameter names uniqueness
+ * @modules jdk.compiler/com.sun.tools.doclint
+ * @build DocLintTester
+ * @run main DocLintTester -ref DuplicateParamTest.out DuplicateParamTest.java
+ */
+
+/** . */
+public class DuplicateParamTest {
+
+    /**
+     * Test.
+     *
+     * @param s one
+     * @param s two
+     * @param s three
+     * 
+     * @return number
+     */
+    public static int Test(String s) { return s.length(); }
+}
diff --git a/test/tools/doclint/DuplicateParamTest.out b/test/tools/doclint/DuplicateParamTest.out
new file mode 100644
--- /dev/null
+++ b/test/tools/doclint/DuplicateParamTest.out
@@ -0,0 +1,7 @@
+DuplicateParamTest.java:17: warning: @param "s" has already been specified
+     * @param s two
+       ^
+DuplicateParamTest.java:18: warning: @param "s" has already been specified
+     * @param s three
+       ^
+2 warnings
\ No newline at end of file
diff --git a/test/tools/doclint/DuplicateReturnTest.java b/test/tools/doclint/DuplicateReturnTest.java
new file mode 100644
--- /dev/null
+++ b/test/tools/doclint/DuplicateReturnTest.java
@@ -0,0 +1,23 @@
+/*
+ * @test /nodynamiccopyright/
+ * @bug 8081820
+ * @summary Validate return uniqueness
+ * @modules jdk.compiler/com.sun.tools.doclint
+ * @build DocLintTester
+ * @run main DocLintTester -ref DuplicateReturnTest.out DuplicateReturnTest.java
+ */
+
+/** . */
+public class DuplicateReturnTest {
+
+    /**
+     * Test.
+     *
+     * @param s one
+     * 
+     * @return one
+     * @return two
+     * @return three
+     */
+    public static int Test(String s) { return s.length(); }
+}
diff --git a/test/tools/doclint/DuplicateReturnTest.out b/test/tools/doclint/DuplicateReturnTest.out
new file mode 100644
--- /dev/null
+++ b/test/tools/doclint/DuplicateReturnTest.out
@@ -0,0 +1,7 @@
+DuplicateReturnTest.java:19: warning: @return has already been specified
+     * @return two
+       ^
+DuplicateReturnTest.java:20: warning: @return has already been specified
+     * @return three
+       ^
+2 warnings
\ No newline at end of file


More information about the javadoc-dev mailing list