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 #11340: Add ignoreAnnotatedBy property to ParameterNumberCheck #14553
Issue #11340: Add ignoreAnnotatedBy property to ParameterNumberCheck #14553
Conversation
GitHub, generate report |
76980bf
to
4e3fdbc
Compare
GitHub, generate website |
|
||
// xdoc section -- start | ||
@Session | ||
public void ignoredAnnotatedMethod(int a, int b, int c, int d, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have kept the xdoc examples for ignoreAnnotatedBy in the non-enabled way to not grow this PR more than required, as rest of examples are currently non-enabled and it wouldn't make much sense to have just one example enabled while the rest remain the old way.
All the examples for this check can be enabled at once in a separate PR as part of the ongoing issue to Enable the Examples.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, but this should at least be compilable. Also, please use something similar to the example provided in the issue, this is a very popular usage when deserializing/serializing. You can just make your own JsonCreator annotation.
*/ | ||
private boolean shouldIgnoreNumberOfParameters(DetailAST ast) { | ||
// if you override a method, you have no power over the number of parameters |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have removed this comment, because it is more from a philosophical point of view to why the functionality to ignore overridden method was added but does not imparts any helpful technical info.
This comment was marked as outdated.
This comment was marked as outdated.
4e3fdbc
to
e4525b5
Compare
GitHub, generate website |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very good, few items:
|
||
// xdoc section -- start | ||
@Session | ||
public void ignoredAnnotatedMethod(int a, int b, int c, int d, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, but this should at least be compilable. Also, please use something similar to the example provided in the issue, this is a very popular usage when deserializing/serializing. You can just make your own JsonCreator annotation.
src/main/java/com/puppycrawl/tools/checkstyle/checks/sizes/ParameterNumberCheck.java
Outdated
Show resolved
Hide resolved
src/main/java/com/puppycrawl/tools/checkstyle/checks/sizes/ParameterNumberCheck.java
Outdated
Show resolved
Hide resolved
src/main/java/com/puppycrawl/tools/checkstyle/checks/sizes/ParameterNumberCheck.java
Outdated
Show resolved
Hide resolved
src/main/java/com/puppycrawl/tools/checkstyle/checks/sizes/ParameterNumberCheck.java
Outdated
Show resolved
Hide resolved
src/main/java/com/puppycrawl/tools/checkstyle/checks/sizes/ParameterNumberCheck.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One more:
src/test/java/com/puppycrawl/tools/checkstyle/checks/sizes/ParameterNumberCheckTest.java
Show resolved
Hide resolved
e4525b5
to
ebefaf9
Compare
GitHub, generate website |
ebefaf9
to
be124d3
Compare
GitHub, generate website |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Items:
...examples/resources/com/puppycrawl/tools/checkstyle/checks/sizes/parameternumber/Example4.txt
Show resolved
Hide resolved
be124d3
to
4cc9297
Compare
GitHub, generate website |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very good, this is a big win for our users. Thanks @sktpy !!
src/it/java/org/checkstyle/suppressionxpathfilter/XpathRegressionParameterNumberTest.java
Show resolved
Hide resolved
I am in agreement with sentiments at #14553 (comment), namely we can focus on making examples all the "same" when we migrate to actual example test execution. We don't need to make this PR any larger than it is right now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Items
src/main/java/com/puppycrawl/tools/checkstyle/checks/sizes/ParameterNumberCheck.java
Outdated
Show resolved
Hide resolved
void method3(int a, int b, int c) {} | ||
|
||
@Deprecated | ||
void method4(int a, int b, int c) {} // violation, 'More than 2 parameters (found 3).' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to be discussed.
When use define java.lang.Deprecated
he usually does not mean to use match fully and exactly.
It can be instruction to figure out exactly a type not a string values. We already have Checks that does this. By import we can be 100% sure on type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nrmancuso , @rnveach , what are your thoughts on this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might be helpful here: #14553 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should go with most simple implementation first (what's in this PR), we can iterate on this as needed. Worst case is that some user has to put both the fully qualified name and the simple annotation name in the config.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have an update here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am good to proceed as-is, @rnveach please share your thoughts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should be consistent with how we treat annotation properties like this with other checks. I don't find it friendly to have to specify both class name and FQCN.
https://checkstyle.org/checks/coding/illegaltype.html#IllegalType
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to make our behavior consistent with other checks and friendly to the user.
We have some check somewhere that requires FQCN and will be smart and reduce it to simple based on the import in the class.
https://checkstyle.org/checks/coding/illegaltype.html
https://checkstyle.org/checks/coding/illegalinstantiation.html
I also feel this shouldn't be delayed if it is going to create almost a breaking change in the fix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have a resolution here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree we can extend to FQCN later on. Lets have basic implementation for now.
With current traffic of PRs I do not have time to mediate on consistency.
f5a2b14
to
4da8113
Compare
src/main/java/com/puppycrawl/tools/checkstyle/checks/sizes/ParameterNumberCheck.java
Outdated
Show resolved
Hide resolved
/** | ||
* Ignore methods and constructors annotated with the specified annotation(s). | ||
*/ | ||
private Set<String> ignoreAnnotatedBy = Set.of(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nrmancuso @romani We have ignoreOverriddenMethods
which also ignores methods based on annotation of Override
. Is there some reason we aren't combining these 2 to make the configuration for this check more reasonable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking the same, but then I read:
#11340 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could deprecate this property, and remove it it the next major version bump.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have a resolution here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can leave both for now, let’s create an issue to discuss deprecation of ignoreOverriddenMethods.
@sktpy please open an issue for this, and share the link here so we can move on
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rnveach please continue review
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can leave both for now
lets not deprecate for now, they should not conflict with each other if user in not doing good job in configuration of them.
src/main/java/com/puppycrawl/tools/checkstyle/checks/sizes/ParameterNumberCheck.java
Show resolved
Hide resolved
1caf6f1
to
2298fd5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok to merge
2c761c7
to
bf078ff
Compare
GH made a merge commit by default. I didn't use the dropdown option. |
bf078ff
to
ec83b47
Compare
Rebased over latest master. |
Resolves #11340
Old Doc(site), New Doc(site)
Regression: (Report)
Differences Found (expected):
Deprecated
is used as the value for theignoreAnnotatedBy
(selected for the purpose that it would produce some differences being a commonly used annotation)Removed violations (22): Example (link), rest of the occurrences are similar.
Deprecated
which is specified inignoreAnnotatedBy
property in the patch-config.Diff Regression config: https://gist.githubusercontent.com/sktpy/0c6a38735b3206b86b593a490206e76d/raw/4c033289ef4802e25c473cec5ef58ff49ea8d788/base-config.xml
Diff Regression patch config: https://gist.githubusercontent.com/sktpy/43c4a398aadd414fbe69d75953704597/raw/7f468b2a7e04762d763d7148d81a640dad733091/patch-config.xml