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

add support to detect accesses of fields by specific methods #1105

Conversation

leonardhusmann
Copy link
Contributor

This PR adds a method to the public API of FieldsShould to check if a field has been accessed by methods matching a given predicate. This is checked by a new ArchCondition.

I've diverged a little bit from the original suggestion of this issue: I chose to stay consistent with the current API and return an ArchCondition<JavaField> to allow method chaining, e.g.

fields().that().inSomeCondition()
    .should().notBeAccessedByMethodsThat(...)
    .andShould().notBeFinal()
    .andShould()....

What do you think? Any feedback is highly appreciated :)

Resolves: #857

@leonardhusmann leonardhusmann marked this pull request as ready for review April 29, 2023 22:52
@codecholeric codecholeric force-pushed the feature/detect-reference-for-fields-in-methods branch 2 times, most recently from 020ea0e to 3cda1d4 Compare October 8, 2023 15:17
@codecholeric
Copy link
Collaborator

Thanks a lot for adding this! 😃 And sorry that it took me so long to look at it! First of all, what do you mean by

| return an ArchCondition<JavaField> to allow method chaining

? I don't see how returning that would allow chaining as in the example? But in any case, what you did looks consistent, so thanks 🙂 Only thing I noticed is that for all the other methods we have a positive and negative form and I realized that there might be use cases where users want to combine this with a noFields start of a rule. So I added the inverted version (and adjusted the test, because I think that was a little too much mingling, i.e. it deserves it's own test). What do you think?

Independently of that, retrospectively I should have added something smarter like a generic not() function to the API 🙈 Instead of "duplicating" every method. But it's already a little inconsistent between classes and fields 😒 So maybe at some point we will release a 2.0.0 and clean up / consolidate the rules API again...

@codecholeric
Copy link
Collaborator

Anyway, what do you think about the review changes in my commit? If everything looks good to you I'd squash everything into one commit...

@leonardhusmann
Copy link
Contributor Author

Hi, thank your for your feedback 😃

First of all, what do you mean by

This is meant with regards to the initial suggestion in the issue from April '22. What I meant by this is that the arguments (DescribedPredicate) are passed as parameters and the function returns the ArchCondition. Just as you did it in your first answer in the thread of the issue 😃.

Apart from that: thank your for the review changes, they make a lot of sense :) So everything looks good to me 👍

Adds `FieldsShould.{be/notBe}AccessedByMethodsThat(predicate)` to the rules API.

Issue: TNG#857
Signed-off-by: Leonard Husmann <[email protected]>
@codecholeric codecholeric force-pushed the feature/detect-reference-for-fields-in-methods branch from 3cda1d4 to 890c3ce Compare November 4, 2023 16:10
@codecholeric codecholeric changed the title add support to detect references of fields in methods add support to detect accesses of fields by specific methods Nov 4, 2023
@codecholeric codecholeric self-requested a review November 4, 2023 16:15
@codecholeric
Copy link
Collaborator

Cool, then thanks a lot again, squashed, rebased and now merged 😃

@codecholeric codecholeric merged commit e68956d into TNG:main Nov 4, 2023
21 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.

[How to] Detect reference for field in methods
2 participants