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 #11340: Add ignoreAnnotatedBy property to ParameterNumberCheck #14553

Merged
merged 1 commit into from Mar 20, 2024

Conversation

sktpy
Copy link
Contributor

@sktpy sktpy commented Feb 26, 2024

Resolves #11340

Old Doc(site), New Doc(site)


Regression: (Report)

Differences Found (expected):
Deprecated is used as the value for the ignoreAnnotatedBy(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
public static <K, V> ImmutableSortedMap<K, V> of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4) {
  • Method above contains 8 params, while maximum(by default) allowed are 7,
  • This is no longer a violation because it is annotated by Deprecated which is specified in ignoreAnnotatedBy property in the patch-config.
  • This is the intended behaviour.

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

@sktpy sktpy marked this pull request as draft February 26, 2024 17:18
@sktpy
Copy link
Contributor Author

sktpy commented Feb 26, 2024

GitHub, generate report

@sktpy sktpy force-pushed the issue-11340-ignore-annotated-by branch 2 times, most recently from 76980bf to 4e3fdbc Compare February 26, 2024 19:03
@sktpy
Copy link
Contributor Author

sktpy commented Feb 26, 2024

GitHub, generate website


// xdoc section -- start
@Session
public void ignoredAnnotatedMethod(int a, int b, int c, int d,
Copy link
Contributor Author

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.

Copy link
Member

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
Copy link
Contributor Author

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.

@sktpy

This comment was marked as outdated.

@sktpy sktpy marked this pull request as ready for review February 26, 2024 20:31
@nrmancuso nrmancuso self-requested a review February 26, 2024 23:56
@nrmancuso nrmancuso self-assigned this Feb 26, 2024
@sktpy sktpy force-pushed the issue-11340-ignore-annotated-by branch from 4e3fdbc to e4525b5 Compare February 27, 2024 16:01
@sktpy
Copy link
Contributor Author

sktpy commented Feb 27, 2024

GitHub, generate website

Copy link
Member

@nrmancuso nrmancuso left a 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,
Copy link
Member

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.

Copy link
Member

@nrmancuso nrmancuso left a comment

Choose a reason for hiding this comment

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

One more:

@sktpy sktpy marked this pull request as draft February 28, 2024 04:53
@sktpy sktpy force-pushed the issue-11340-ignore-annotated-by branch from e4525b5 to ebefaf9 Compare February 28, 2024 10:21
@sktpy
Copy link
Contributor Author

sktpy commented Feb 28, 2024

GitHub, generate website

@sktpy sktpy force-pushed the issue-11340-ignore-annotated-by branch from ebefaf9 to be124d3 Compare February 28, 2024 10:39
@sktpy
Copy link
Contributor Author

sktpy commented Feb 28, 2024

GitHub, generate website

@sktpy sktpy marked this pull request as ready for review February 28, 2024 11:16
Copy link
Member

@nrmancuso nrmancuso left a comment

Choose a reason for hiding this comment

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

Items:

@sktpy sktpy force-pushed the issue-11340-ignore-annotated-by branch from be124d3 to 4cc9297 Compare February 28, 2024 15:00
@sktpy
Copy link
Contributor Author

sktpy commented Feb 28, 2024

GitHub, generate website

Copy link
Member

@nrmancuso nrmancuso left a 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 !!

@nrmancuso nrmancuso assigned romani and unassigned nrmancuso Feb 28, 2024
@nrmancuso
Copy link
Member

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.

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.

Items

void method3(int a, int b, int c) {}

@Deprecated
void method4(int a, int b, int c) {} // violation, 'More than 2 parameters (found 3).'
Copy link
Member

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.

Copy link
Member

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?

Copy link
Contributor Author

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)

Copy link
Member

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.

Copy link
Contributor Author

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?

Copy link
Member

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

Copy link
Member

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

Copy link
Member

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.

Copy link
Contributor Author

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?

Copy link
Member

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.

/**
* Ignore methods and constructors annotated with the specified annotation(s).
*/
private Set<String> ignoreAnnotatedBy = Set.of();
Copy link
Member

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?

Copy link
Contributor Author

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)

Copy link
Member

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.

Copy link
Contributor Author

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?

Copy link
Member

@nrmancuso nrmancuso Mar 14, 2024

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

Copy link
Contributor Author

@sktpy sktpy Mar 14, 2024

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

@rnveach please continue review

Copy link
Member

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/xdocs/checks/sizes/parameternumber.xml.template Outdated Show resolved Hide resolved
@sktpy sktpy force-pushed the issue-11340-ignore-annotated-by branch 2 times, most recently from 1caf6f1 to 2298fd5 Compare March 6, 2024 18:02
@rnveach rnveach assigned romani and unassigned rnveach Mar 7, 2024
@nrmancuso nrmancuso assigned rnveach and unassigned romani Mar 14, 2024
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.

ok to merge

@rnveach
Copy link
Member

rnveach commented Mar 18, 2024

@rnveach rnveach force-pushed the issue-11340-ignore-annotated-by branch from 2c761c7 to bf078ff Compare March 18, 2024 14:52
@rnveach
Copy link
Member

rnveach commented Mar 18, 2024

GH made a merge commit by default. I didn't use the dropdown option.

@sktpy sktpy force-pushed the issue-11340-ignore-annotated-by branch from bf078ff to ec83b47 Compare March 18, 2024 15:48
@sktpy
Copy link
Contributor Author

sktpy commented Mar 18, 2024

Rebased over latest master.

@rnveach rnveach merged commit deb1121 into checkstyle:master Mar 20, 2024
112 of 113 checks passed
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.

Add ignoreMethodAnnotatedBy property to ParameterNumberCheck
4 participants