New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JDK-8272374: doclint should report missing "body" comments #5106
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -182,9 +182,6 @@ public Void scan(DocCommentTree tree, TreePath p) { | |
reportMissing("dc.missing.comment"); | ||
return null; | ||
} | ||
|
||
|
||
|
||
} else { | ||
if (tree == null) { | ||
if (isDefaultConstructor()) { | ||
|
@@ -195,6 +192,18 @@ public Void scan(DocCommentTree tree, TreePath p) { | |
reportMissing("dc.missing.comment"); | ||
} | ||
return null; | ||
} else if (tree.getFirstSentence().isEmpty() && !isOverridingMethod) { | ||
if (tree.getBlockTags().isEmpty()) { | ||
reportMissing("dc.empty.comment"); | ||
return null; | ||
} else { | ||
DocTree firstTag = tree.getBlockTags().get(0); | ||
// Don't report an empty description if the comment begins with @deprecated, | ||
// because javadoc will use the content of that tag in summary tables. | ||
if (firstTag.getKind() != DocTree.Kind.DEPRECATED) { | ||
env.messages.report(MISSING, Kind.WARNING, tree, "dc.empty.description"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a reason to not use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It doesn't have the right signature. |
||
} | ||
} | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
EmptyAuthorTest.java:11: warning: no description for @author | ||
/** @author */ | ||
^ | ||
EmptyAuthorTest.java:13: warning: no description for @author | ||
* @author | ||
^ | ||
1 warning | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
|
||
/* | ||
* @test /nodynamiccopyright/ | ||
* @bug 8272374 | ||
* @summary doclint should report missing "body" comments | ||
* @modules jdk.javadoc/jdk.javadoc.internal.doclint | ||
* @build DocLintTester | ||
* @run main DocLintTester -Xmsgs:-missing EmptyDescriptionTest.java | ||
* @run main DocLintTester -Xmsgs:missing -ref EmptyDescriptionTest.out EmptyDescriptionTest.java | ||
*/ | ||
|
||
/** . */ | ||
public class EmptyDescriptionTest { | ||
// a default constructor triggers its own variant of "no comment" | ||
|
||
// no comment | ||
public int f1; | ||
|
||
// empty comment | ||
/** */ | ||
public int f2; | ||
|
||
// empty description | ||
/** | ||
* @since 1.0 | ||
*/ | ||
public int f3; | ||
|
||
// deprecated: no diagnostic | ||
/** | ||
* @deprecated do not use | ||
*/ | ||
public int f4; | ||
|
||
// no comment | ||
public int m1() { return 0; } | ||
|
||
// empty comment | ||
/** */ | ||
public int m2() { return 0; } | ||
|
||
// empty description | ||
/** | ||
* @return 0 | ||
*/ | ||
public int m3() { return 0; } | ||
|
||
// deprecated: no diagnostic | ||
/** | ||
* @deprecated do not use | ||
* @return 0 | ||
*/ | ||
public int m4() { return 0; }; | ||
|
||
/** | ||
* A class containing overriding methods. | ||
* Overriding methods with missing/empty comments do not generate messages | ||
* since they are presumed to inherit descriptions as needed. | ||
*/ | ||
public static class Nested extends EmptyDescriptionTest { | ||
/** . */ Nested() { } | ||
|
||
@Override | ||
public int m1() { return 1; } | ||
|
||
// empty comment | ||
/** */ | ||
@Override | ||
public int m2() { return 1; } | ||
|
||
// empty description | ||
/** | ||
* @return 1 | ||
*/ | ||
@Override | ||
public int m3() { return 1; } | ||
|
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
EmptyDescriptionTest.java:13: warning: use of default constructor, which does not provide a comment | ||
public class EmptyDescriptionTest { | ||
^ | ||
EmptyDescriptionTest.java:17: warning: no comment | ||
public int f1; | ||
^ | ||
EmptyDescriptionTest.java:21: warning: empty comment | ||
public int f2; | ||
^ | ||
EmptyDescriptionTest.java:25: warning: no initial description | ||
* @since 1.0 | ||
^ | ||
EmptyDescriptionTest.java:36: warning: no comment | ||
public int m1() { return 0; } | ||
^ | ||
EmptyDescriptionTest.java:40: warning: empty comment | ||
public int m2() { return 0; } | ||
^ | ||
EmptyDescriptionTest.java:44: warning: no initial description | ||
* @return 0 | ||
^ | ||
7 warnings |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
EmptyExceptionTest.java:13: warning: no description for @exception | ||
/** @exception NullPointerException */ | ||
^ | ||
EmptyExceptionTest.java:15: warning: no description for @exception | ||
* @exception NullPointerException | ||
^ | ||
1 warning |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
EmptyParamTest.java:13: warning: no description for @param | ||
/** @param i */ | ||
^ | ||
EmptyParamTest.java:15: warning: no description for @param | ||
* @param i | ||
^ | ||
1 warning | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
EmptyReturnTest.java:13: warning: no description for @return | ||
/** @return */ | ||
^ | ||
EmptyReturnTest.java:15: warning: no description for @return | ||
* @return | ||
^ | ||
1 warning | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we only check the first block tag here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Various reasons,
@deprecated
or to replace the existing body description with@deprecated reason-why-deprecated
@see
@param
@return
etc and then have the@deprecated
tag.That being said, it would be easy enough to change the code to check for any instance of
@deprecated
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that the downstream code does not impose any ordering restrictions on the tags, it is probably with doing the same here.