Skip to content

Add support for inline return tag in SummaryJavadoc#10772

Merged
rnveach merged 1 commit intocheckstyle:masterfrom
octylFractal:feature/inline-return-tag-javadoc
Mar 19, 2022
Merged

Add support for inline return tag in SummaryJavadoc#10772
rnveach merged 1 commit intocheckstyle:masterfrom
octylFractal:feature/inline-return-tag-javadoc

Conversation

@octylFractal
Copy link
Copy Markdown
Contributor

@octylFractal octylFractal commented Sep 1, 2021

@octylFractal
Copy link
Copy Markdown
Contributor Author

octylFractal commented Sep 1, 2021

I seem to have misread the original issue, this only covers SummaryJavadoc and not JavadocMethod -- should I make a separate issue for this or combine both additions as a single feature PR?

Edit: I have detached this PR from the issue, this is now a PR without a pre-filed issue. Let me know if you'd like me to file a formal issue for this first.

Copy link
Copy Markdown
Member

@pbludov pbludov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@octylFractal according to the specs, the inline return tag is allowed only for methods.
Please add validation for this (something like getBlockCommentAst().getParent().getParent().getType() == TokenTypes.METHOD_DEF).

octylFractal added a commit to octylFractal/checkstyle that referenced this pull request Sep 4, 2021
@octylFractal octylFractal force-pushed the feature/inline-return-tag-javadoc branch from 8ac6386 to 7f5c943 Compare September 4, 2021 07:23
octylFractal added a commit to octylFractal/checkstyle that referenced this pull request Sep 4, 2021
@octylFractal octylFractal force-pushed the feature/inline-return-tag-javadoc branch from 7f5c943 to 82bdeb0 Compare September 4, 2021 07:28
octylFractal added a commit to octylFractal/checkstyle that referenced this pull request Sep 4, 2021
@octylFractal octylFractal force-pushed the feature/inline-return-tag-javadoc branch from 82bdeb0 to 4380726 Compare September 4, 2021 08:20
@octylFractal octylFractal requested a review from pbludov September 4, 2021 08:21
@pbludov pbludov requested a review from rnveach September 4, 2021 10:07
@pbludov pbludov assigned rnveach and unassigned pbludov Sep 4, 2021
@rnveach
Copy link
Copy Markdown
Contributor

rnveach commented Sep 4, 2021

I seem to have misread the original issue

@octylFractal What is original issue? Also rebase onto latest master to resolve CI failure.

@octylFractal
Copy link
Copy Markdown
Contributor Author

Originally I thought this applied to #9745, but that is for the JavadocMethod check, not SummaryJavadoc which this PR modifies.

@rnveach
Copy link
Copy Markdown
Contributor

rnveach commented Sep 4, 2021

@octylFractal Then create a new issue for it showing its a similar problem and attach this PR to it. Issue description can be very similar to current issue. @pbludov Will review and approve it if it is also valid.

Do know that these checks are deprecated and need to be re-written using the Javadoc parser and made into AbstractJavadocChecks. As this issue shows, regexp parsing is error prone. We can continue this PR if you wish still.
Edit: This is an AbstractJavadocCheck...

@@ -1,4 +1,6 @@
at.clause.order=Block tags have to appear in the order ''{0}''.
inlineReturn.javaDoc=Forbidden inline @return.
inlineReturn.javaDoc.wrongMemberType=@return is placed on the wrong type of member.
Copy link
Copy Markdown
Contributor

@rnveach rnveach Sep 4, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@octylFractal @pbludov To me, this is not clear from the original issue. I was under the impression we were suppressing a false violation. But are we expanding Check to catch more things? It seems issue is not clear in definition of what to do and it should closely match the PR. The issue and title is what is used to put what we are changing in the release notes.

To me, check is only checking the summary sentence and that another check should be made to identify tags (inline or not) that are used in the wrong place. We need to keep checks from exploding with too much functionality. We have already seen this in other checks that it becomes a burden and they need to be rewritten.

To me, if Javadoc tool accepts inline return as a summary, why should we have an option to forbid it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was my feeling as well, but I figured that @pbludov knew better that I did.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with @rnveach. The commit message should be changed to something like "SummaryJavadoc shouldn't report javadocs with inline return tag"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove new messages, validation should stay be done by same messages.

@romani
Copy link
Copy Markdown
Member

romani commented Sep 4, 2021

@octylFractal , please put in commit and PR description link/ref to issue. I need to confirm original issue first before dive in implementation details.

Copy link
Copy Markdown
Member

@romani romani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need to see definition of target problem in format as we demand for issue ( reproduced by cli)

@octylFractal
Copy link
Copy Markdown
Contributor Author

I filed #10776, updating PR now...

@octylFractal octylFractal force-pushed the feature/inline-return-tag-javadoc branch from 4380726 to debc2b0 Compare September 4, 2021 16:45
@pbludov pbludov self-requested a review September 6, 2021 11:20
Copy link
Copy Markdown
Member

@romani romani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@octylFractal ,

thanks a lot for creation of issue! I updated it and approved it.
Please continue updating this PR.

items:

@@ -1,4 +1,6 @@
at.clause.order=Block tags have to appear in the order ''{0}''.
inlineReturn.javaDoc=Forbidden inline @return.
inlineReturn.javaDoc.wrongMemberType=@return is placed on the wrong type of member.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove new messages, validation should stay be done by same messages.

@romani romani assigned romani and unassigned rnveach Dec 22, 2021
@octylFractal octylFractal force-pushed the feature/inline-return-tag-javadoc branch 3 times, most recently from d36349c to b35bea3 Compare February 20, 2022 06:24
Copy link
Copy Markdown
Member

@romani romani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

item:

@octylFractal octylFractal force-pushed the feature/inline-return-tag-javadoc branch from b35bea3 to 1745708 Compare February 20, 2022 10:12
Copy link
Copy Markdown
Member

@romani romani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you check how you update works on your private projects ?
Regression testing did not find any differences, it is ok but in the same time signal that projects that we use does not have target javdocs, it would be awesome to run on real code that use this tag (but it is not critical).

items:

@octylFractal octylFractal force-pushed the feature/inline-return-tag-javadoc branch 3 times, most recently from f93b39a to 39e32aa Compare February 21, 2022 04:06
@octylFractal
Copy link
Copy Markdown
Contributor Author

Did you check how you update works on your private projects ?
Regression testing did not find any differences, it is ok but in the same time signal that projects that we use does not have target javdocs, it would be awesome to run on real code that use this tag (but it is not critical).

I just made some changes over at EngineHub/WorldEdit@version/7.2.x...testing/checkstyle-inline-return, and this code now passes using this branch. I will be merging this back into version/7.2.x and eventually master once this PR is merged, if you would like to add this codebase to the regression tests.

@romani
Copy link
Copy Markdown
Member

romani commented Feb 22, 2022

@octylFractal , your project enforcing error level severity , do you enforce following this by each commit ? if yes we can add your project to regression testing in our CI to make sure that any update in checkstyle executes on your code base and pass before merging.
Example:

- CMD2="./.ci/validation.sh no-error-pgjdbc"

you can send PR to append to us yourself.
Lets discuss this outside of this PR.

@romani romani force-pushed the feature/inline-return-tag-javadoc branch from 39e32aa to a233d96 Compare February 22, 2022 04:23
@octylFractal octylFractal force-pushed the feature/inline-return-tag-javadoc branch from a233d96 to 7cd6a8b Compare February 23, 2022 03:46
@romani
Copy link
Copy Markdown
Member

romani commented Feb 23, 2022

#11337 is created.

@romani romani force-pushed the feature/inline-return-tag-javadoc branch from 7cd6a8b to f5be3bb Compare February 23, 2022 04:33
@romani
Copy link
Copy Markdown
Member

romani commented Feb 23, 2022

I pushed formatting indentation corrections to make it more pretty to my mind.

Copy link
Copy Markdown
Member

@romani romani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok to merge.

@romani romani assigned rnveach and unassigned romani Feb 23, 2022

package com.puppycrawl.tools.checkstyle.checks.javadoc.summaryjavadoc;

class InputSummaryJavadocInlineReturn {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need some more examples.
What about if there is text before the {@return}.
What about if there is text after the {@return}.
What about if the content of {@return} spans multiple lines?
What about if a void method uses the {@return}? Does the javadoc flag an error on this? Do we?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will check the first 3, for the last one javadoc produces a hard error:

SummaryJavadocNewInlineReturn.java:3: error: invalid use of @return
     * {@return a foo that is {@code 0}}
       ^

so I think checking for that in checkstyle is redundant.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about if there is text before the {@return}.

javadoc produces a warning. Should I add a warning to checkstyle as well? Should I add a test that this is accepted by checkstyle?

SummaryJavadocNewInlineReturn.java:5: warning: {@return} not at beginning of description
     * Starting text, {@return a foo that is {@code 0}} extra text afterwards.
                      ^

What about if there is text after the {@return}.

This is normal and allowed, I will add a test that it does not produce a violation.

What about if the content of {@return} spans multiple lines?

Using a normal newline, this produces output like the following:

javadoc render

Using <br>, this produces output like the following:

javadoc render

I do not know if checkstyle should produce a message for either of these. Please inform me as to what is appropriate.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for the last one javadoc produces a hard error:

Is there any issue adding this? We specifically have another where it also produces an error by the javadoc.
#10772 (comment)

I will add a test

Ok.

javadoc produces a warning. Should I add a warning to checkstyle as well?

@romani please comment on scope of issue.

Please inform me as to what is appropriate.

Please update your post to include the raw code of the javadoc, so I can correlate that to the javadoc printouts you provided.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not do what is already done by javadoc

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update your post to include the raw code of the javadoc, so I can correlate that to the javadoc printouts you provided.

/**
 */
public class SummaryJavadocNewInlineReturn {
    /**
     * {@return a foo that is {@code 0}<br>
     * this takes a lot<br>
     * of lines to explain<br>
     * so it is quite long}
     */
    public int foo() {
    }
}

Remove the <br>s for the first output.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not know if checkstyle should produce a message for either of these.

As far as I can tell, the javadoc accepts everything as the summary. Checkstyle should do the same.

Were you asking for advice on something else?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, thank you.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is all done now.


// violation below
/**
* {@return}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this violation because the return is completely empty?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, ergo there is no summary.

Copy link
Copy Markdown
Member

@romani romani Mar 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might good to add reason to comment
// violation below, because the return is completely empty
Or any other way to not conflict with actual message.

Better to be very clear in tests.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

/**
* {@return nothing, this is a field}
*/
private static final byte NOT_A_METHOD = 0; // ok
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry if I missed it, but can you point to where we analyzed how the javadoc tool behaves with this or the class one?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't analyze it prior, but just now I tested:

public class SummaryJavadocNewInlineReturn {
    /** 
     * {@return invalid}
     */
    public final int foo = 0;
}
$ javadoc SummaryJavadocNewInlineReturn.java
Loading source file SummaryJavadocNewInlineReturn.java...
Constructing Javadoc information...
Building index for all the packages and classes...
Standard Doclet version 16.0.2+7
Building tree for all the packages and classes...
Generating ./SummaryJavadocNewInlineReturn.html...
SummaryJavadocNewInlineReturn.java:3: error: invalid use of @return
     * {@return invalid}
       ^
[other messages removed]

So javadoc produces a hard error when this is placed on a non-method class member. Therefore, we don't check it in checkstyle.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@octylFractal , please repost your comment to issue.

PR in highly unlikely to be reviewed later on, but issues are good source of our decisions to review through time. Javadoc tool might change behavior and will be puzzleed why we did/didn't do something.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@romani
Copy link
Copy Markdown
Member

romani commented Mar 9, 2022

@octylFractal , please rebase on latest our master, we merged another update in this check. Sorry about this.
I hope to merge this PR very soon.
Please reply "done" or any other question in unresolved review comments.

@octylFractal octylFractal force-pushed the feature/inline-return-tag-javadoc branch from f5be3bb to 3c0f78f Compare March 12, 2022 18:25
@octylFractal
Copy link
Copy Markdown
Contributor Author

PR is rebased.

@romani
Copy link
Copy Markdown
Member

romani commented Mar 12, 2022

@octylFractal octylFractal force-pushed the feature/inline-return-tag-javadoc branch from 3c0f78f to f1f4fcf Compare March 12, 2022 20:01
@octylFractal
Copy link
Copy Markdown
Contributor Author

The semaphore failure seems unrelated. Let me know if I need to change anything.

@romani
Copy link
Copy Markdown
Member

romani commented Mar 13, 2022

Relaunched

@rnveach rnveach merged commit cc90b04 into checkstyle:master Mar 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Inline @return tag does not pass SummaryJavadocCheck

4 participants