Skip to content

update WriteTagCheck to use AST of javadoc #19150

Closed

Description

@romani

https://checkstyle.org/checks/javadoc/writetag.html#WriteTag

we introduced new javadoc AST in scope of #17514

Now it is time to migrate WriteTagCheck Check to use AST, rather than regexp for parsing of javadoc.

Whole design should stay as is, same properties.
But check should extend extends AbstractJavadocCheck and do all logic based on AST nodes.
There are already bunch of Checks that doing this, so look around for examples.

remove suppresion that is mentioned at #11166

Activity

  1. lithops-zty commented on Mar 8, 2026

    @lithops-zty
    Contributor

    I'm on it.

  2. lithops-zty commented on Mar 8, 2026

    @lithops-zty
    Contributor

    Hi @romani , I am trying to rewrite the check using Javadoc AST, but am struggling to find a way to implement the tagFormat option. tagFormat is a user-specified regexp to match raw texts that appear after block tags, but I found getting these raw texts rather tricky.

    What I have tried

    Instinctively I tried to get the texts from TEXT under DESCRIPTION:

    JavadocUtil.findFirstToken(javadocTagSection.getFirstChild(),
        JavadocCommentsTokenTypes.DESCRIPTION).getFirstChild().getText();
    )

    The problem

    The above approach fails in various cases:

    1. @param var description:
    |--JAVADOC_BLOCK_TAG -> JAVADOC_BLOCK_TAG [4:4]
    |   `--PARAM_BLOCK_TAG -> PARAM_BLOCK_TAG [4:4]
    |       |--AT_SIGN -> @ [4:4]
    |       |--TAG_NAME -> param [4:5]
    |       |--TEXT ->   [4:10]
    |       |--PARAMETER_NAME -> var [4:11]
    |       `--DESCRIPTION -> DESCRIPTION [4:14]
    |           `--TEXT ->  description [4:14]
    

    description text does not contain the variable name which is stored separately;

    1. @return <p>some html</p>:
    |--JAVADOC_BLOCK_TAG -> JAVADOC_BLOCK_TAG [6:4]
    |   `--RETURN_BLOCK_TAG -> RETURN_BLOCK_TAG [6:4]
    |       |--AT_SIGN -> @ [6:4]
    |       |--TAG_NAME -> return [6:5]
    |       |--TEXT ->   [6:11]
    |       `--DESCRIPTION -> DESCRIPTION [6:12]
    |           `--HTML_ELEMENT -> HTML_ELEMENT [6:12]
    |               ...
    

    DESCRIPTION has no TEXT but parsed HTML_ELEMENT

    1. @see java.lang.Object:
    |--JAVADOC_BLOCK_TAG -> JAVADOC_BLOCK_TAG [5:4]
    |   `--SEE_BLOCK_TAG -> SEE_BLOCK_TAG [5:4]
    |       |--AT_SIGN -> @ [5:4]
    |       |--TAG_NAME -> see [5:5]
    |       |--TEXT ->   [5:8]
    |       `--REFERENCE -> REFERENCE [5:9]
    |           `--IDENTIFIER -> java.lang.Object [5:9]
    

    @see has no DESCRIPTION but a REFERENCE node.

    It seems very hard to reconstruct raw texts from parsed AST nodes. May I know if there is a simple way to get the raw texts?

  3. romani commented on Mar 8, 2026

    @romani
    MemberAuthor

    No simple way, each tag will have special way to be flattened back to string.
    But you have all in tree, just a bit more java code to be written

  4. added a commit that references this issue on Mar 12, 2026
  5. romani commented on Mar 15, 2026

    @romani
    MemberAuthor

    pay attention for #18059
    where we remove finals from methods of
    src/main/java/com/puppycrawl/tools/checkstyle/checks/javadoc/AbstractJavadocCheck.java

    if required apply same to your PR to let continue

  6. Krish-876 commented on Mar 20, 2026

    @Krish-876
    Contributor

    Hi, I see there is draft PR but no updates recently.
    Are you still actively working on this?
    If not I would like to help or continue.

  7. lithops-zty commented on Mar 20, 2026

    @lithops-zty
    Contributor

    Hi @Krish-876 Thank you for your interest in helping with this issue! I am working on this now and will complete the PR soon.

  8. Krish-876 commented on Mar 20, 2026

    @Krish-876
    Contributor

    Thanks for the update
    I’ll step back from this issue then. Please let me know if any help is needed.

  9. added 5 commits that reference this issue on Mar 20, 2026
  10. 16 remaining items

  11. added a commit that references this issue on Jun 25, 2026
  12. added a commit that references this issue on Jul 12, 2026
  13. romani commented on Jul 17, 2026

    @romani
    MemberAuthor

    fix for issue is at #19193 is almost done, waiting for author to followup.

  14. added 6 commits that reference this issue on Jul 18, 2026
  15. added 2 commits that reference this issue on Jul 21, 2026
  16. added this to the 13.9.0 milestone on Jul 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions