Skip to content
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

Issue #2427: added customizable javadoc tokens #3512

Merged
merged 1 commit into from
Nov 1, 2016

Conversation

rnveach
Copy link
Member

@rnveach rnveach commented Oct 23, 2016

Issue #2427.

Added acceptable and required javadoc tokens. Code was mostly copied from TreeWalker which this class is mimicking.
All javadoc checks required getRequiredJavadocTokens to be added.

Questions:
1)
The issue made note of an area that had documentation on this already but was removed.
Was that documentation valid that the 2 tokens are optional?
Are there any other optional tokens for the javadoc checks? I didn't see anything jump out when glancing over.

Some things to note:
1)
We needed some place to validate that the javadoc tokens set for the check are correct and require us to be able to throw a CheckstyleException. I did this in init and so had to add the exception to the throws clause, and this is why there is an update in FallThroughCheck. I don't see any other place we can do this.
I brought this up before where none of the AbstractCheck methods allow throwing an exception, even CheckstyleException and I don't think we should use runtime exceptions.
If your ok with it, I think we should change all the methods to be able to throw CheckstyleExceptions.

Javadoc's walk method changed slightly because I think there is a bug with waitsForProcessing and when we loop while (curNode != null && toVisit == null) { more than once since the value isn't updated.
I will try to find a test to show this and add it.

AtClauseOrderCheck changed slightly to not loop through the children, but to use the visit token's power. This would be helpful if the token appears in other places than a child of the root.

@codecov-io
Copy link

codecov-io commented Oct 24, 2016

Current coverage is 100% (diff: 100%)

Merging #3512 into master will not change coverage

@@           master   #3512   diff @@
=====================================
  Files         273     273          
  Lines       13074   13170    +96   
  Methods         0       0          
  Messages        0       0          
  Branches     2978    3004    +26   
=====================================
+ Hits        13074   13170    +96   
  Misses          0       0          
  Partials        0       0          

Powered by Codecov. Last update dda0b9e...ad58563

@romani
Copy link
Member

romani commented Oct 24, 2016

Was that documentation valid where the 2 tokens are optional?

I doubt it was valid. It was imaginary config.

Are there any other optional tokens for the javadoc checks?

We do not have. We have only 6 Checks that extends AbstractJavadocCheck:
AtclauseOrderCheck
JavadocParagraphCheck
JavadocTagContinuationIndentationCheck
NonEmptyAtclauseDescriptionCheck
SingleLineJavadocCheck
SummaryJavadocCheck

All of them were created to cover Google style, right after ANTLR grammar was introduced. Almost all of them are simple Checks. Only NonEmptyAtclauseDescriptionCheck could have some reasons to be customized. But it was missed from our attention during implementation as no customization was required for Google style.

@romani
Copy link
Member

romani commented Oct 24, 2016

even CheckstyleException and I don't think we should use runtime exceptions.

we should not pollute method signatures with checked exceptions internally.
Checked exception give no extra details in comparison to not specifying it at all. It is already clear that there is possibility of exception in code. That is why non of Checks have it - when can throw all possible exceptions and TreeWalker convert them to CheckstyleException to deliver to outside of library as some exception that happened in checkstyle to easily let main code distinguish it and process.
I would use IllegalStateException , to let it fly to TreeWalker as any other exception in Checks.

I will try to find a test to show this and add it.

Such unclear fixes should beeasily caught by cobertura. If you do not have problem, that is strange.

AtClauseOrderCheck changed slightly to not loop through the children, but to use the visit token's power. This would be helpful if the token appears in other places than a child of the root.

hmmm, it is always a decision point to make Check stateless or stateful (you added a field - it become stateful). I always guided other to make Check stateless is there is no performace hit by it in comparison to statefull implementation.
In the future: Stateless Checks will be marked by us and TreeWalker will run them in MT mode, stateful Checks will run as they run right now.

@rnveach
Copy link
Member Author

rnveach commented Oct 25, 2016

I doubt it was valid. It was imaginary config.
We do not have.

Then I will leave validating javadoc tokens till later, as any code I write for it now will remain untested until that time.

I reverted changes to AtClauseOrderCheck.

Stateless Checks will be marked by us and TreeWalker will run them in MT mode, stateful Checks will run as they run right now.

I will start an email chain discussing this with you. :)

we should not pollute method signatures with checked exceptions internally.

CheckstyleException is ours, so I don't really consider it polluting by adding it. My main reason for wanting it there is because I dislike wrapping exception upon exception multiple times making the final printed exception overly complex with Caused by. But I am also unsure when something should and shouldn't be a runtime exception.
I reverted the changes and used IllegalStateException.

Such unclear fixes should be easily caught by cobertura. If you do not have problem, that is strange.

Cobertura just checks for dead code. It doesn't check for logic errors, which this is. Just because a method runs and returns a result, doesn't mean it returns the correct result.
I added the check testVisitLeaveToken to show the issue. If you comment out these 3 new lines in AbstractJavadocCheck:

                 if (toVisit == null) {
                     curNode = curNode.getParent();
+                    if (curNode != null) {
+                        waitsForProcessing = shouldBeProcessed(curNode);
+                    }

you will get more calls to leaveJavadocToken than to visitJavadocToken. They should be 1 to 1. The reason for the issue is waitsForProcessing is a variable with a value based on curNode. When curNode changes, waitsForProcessing should too, but it wasn't.
Without these lines, the test will fail with: AssertionError: expected:<406> but was:<464>

@rnveach rnveach force-pushed the issue_2427 branch 2 times, most recently from 085c31b to c5ade4d Compare October 25, 2016 02:27
@romani
Copy link
Member

romani commented Oct 29, 2016

I dislike wrapping exception upon exception multiple times making the final printed exception overly complex with Caused by

yes, but unpleasant code is more often read by engineers.

Code looks good.

please update http://checkstyle.sourceforge.net/writingjavadocchecks.html#Customize_token_types_in_Javadoc_Checks and we good to merge.

@rnveach
Copy link
Member Author

rnveach commented Oct 31, 2016

@romani Done.

Copy link
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.

please address few code review points

@@ -54,6 +54,11 @@
}

@Override
public int[] getRequiredJavadocTokens() {
return getDefaultJavadocTokens();
}
Copy link
Member

Choose a reason for hiding this comment

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

hmm, the whole reason of the issue was to customize NonEmptyAtclauseDescription , but with such method we do not allow customization.
required should be empty array.

Copy link
Member Author

Choose a reason for hiding this comment

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

the whole reason of the issue was to customize NonEmptyAtclauseDescription

I took your reply here to mean there were no optional tokens for any checks.

Was that documentation valid where the 2 tokens are optional?

I doubt it was valid. It was imaginary config.

Are there any other optional tokens for the javadoc checks?

We do not have.

Done in next update.

@@ -73,6 +73,11 @@ public void setOffset(int offset) {
}

@Override
public int[] getRequiredJavadocTokens() {
return getDefaultJavadocTokens();
Copy link
Member

Choose a reason for hiding this comment

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

there should be getAcceptableJavadocTokens usage. We require all.
Please fix in all other cases.

Copy link
Member Author

Choose a reason for hiding this comment

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

Is there a reason for this? getAcceptable's default implementation copies getDefault, so in the end it is the same.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

@rnveach
Copy link
Member Author

rnveach commented Nov 1, 2016

@romani Changes were addressed.
Allowing optional javadoc tokens in NonEmptyAtclauseDescriptionCheck required me to implement this code in XDocsPagesTest so they would appear in the xdocs.

@romani romani merged commit 62926b6 into checkstyle:master Nov 1, 2016
@rnveach rnveach deleted the issue_2427 branch November 1, 2016 21:45
@rnveach rnveach restored the issue_2427 branch November 2, 2016 12:23
@rnveach rnveach deleted the issue_2427 branch November 2, 2016 12:26
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.

None yet

3 participants