Documentation comments will be ignored if they are not placed in an expected place, or if multiple comments are given in an expected place.
It would be good to add a -Xlint category for "dangling doc comments"
Suggested implementation:
When any documentation comment is found, it can be recorded somewhere. When the comment is attached to a declaration, we can record that as well.
Any difference between the two sets indicates dangling comments that have not been attached to a declaration.
Since a source file is scanned top to bottom, it may be enough to use a one-element cache to record the most recent doc comment and whether it has been (or soon will be) attached to a comment. When the next doc comment is found, if the previous one has not been "claimed", then we can give a warning.
It would be good to add a -Xlint category for "dangling doc comments"
Suggested implementation:
When any documentation comment is found, it can be recorded somewhere. When the comment is attached to a declaration, we can record that as well.
Any difference between the two sets indicates dangling comments that have not been attached to a declaration.
Since a source file is scanned top to bottom, it may be enough to use a one-element cache to record the most recent doc comment and whether it has been (or soon will be) attached to a comment. When the next doc comment is found, if the previous one has not been "claimed", then we can give a warning.
- duplicates
-
JDK-8303689 javac -Xlint could/should report on "dangling" doc comments
- Resolved