Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/codeql/codeql-language-guides/javadoc.rst
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ It's now easy to add another conjunct to the ``where`` clause, restricting the q

from Callable c, ParamTag pt
where c.getDoc().getJavadoc() = pt.getParent() and
not c.getAParameter().hasName(pt.getParamName())
not c.getAParameter().hasName(pt.getParamName().regexpReplaceAll(",|:|\\.",""))
select pt, "Spurious @param tag."

Example: Finding spurious @throws tags
Expand Down
12 changes: 7 additions & 5 deletions java/ql/src/Advisory/Documentation/SpuriousJavadocParam.ql
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,24 @@

import java

from Callable callable, ParamTag paramTag, string what, string msg
from Callable callable, ParamTag paramTag, string what, string msg, string paramTagName
where
callable.(Documentable).getJavadoc().getAChild() = paramTag and
(if callable instanceof Constructor then what = "constructor" else what = "method") and
if exists(paramTag.getParamName())
paramTagName = paramTag.getParamName().regexpReplaceAll(",|:|\\.","") and
if exists(paramTagName)
then
// The tag's value is neither matched by a callable parameter name ...
not callable.getAParameter().getName() = paramTag.getParamName() and
not callable.getAParameter().getName() = paramTagName and
// ... nor by a type parameter name.
not exists(TypeVariable tv | tv.getGenericCallable() = callable |
"<" + tv.getName() + ">" = paramTag.getParamName()
"<" + tv.getName() + ">" = paramTagName
) and
msg =
"@param tag \"" + paramTag.getParamName() + "\" does not match any actual parameter of " +
"@param tag \"" + paramTagName + "\" does not match any actual parameter of " +
what + " \"" + callable.getName() + "()\"."
else
// The tag has no value at all.
msg = "This @param tag does not have a value."
select paramTag, msg