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 API to create ArchConditions from predicates #904

Merged
merged 4 commits into from
Jul 10, 2022

Conversation

codecholeric
Copy link
Collaborator

@codecholeric codecholeric commented Jul 7, 2022

So far there has not been any straight forward way to turn a DescribedPredicate into an ArchCondition, even though the semantics are fairly similar (both determine if elements match a certain condition). The reason is, that ArchCondition needs more information than DescribedPredicate. While DescribedPredicate only needs to have some description to be displayed as part of the ArchRule text, ArchCondition additionally needs to describe each single event/violation that occurs. And the way how to do this depends on the predicate (take e.g. "does not have simple name 'Demo'" vs "is no enum" or "does not reside in a package 'com.demo'"). Thus, we have created a generic factory method ArchCondition.from(predicate) and two more convenient "sentence-like" factory methods ArchConditions.{have/be}(predicate) that can be used for most common cases. In any case if the event description does not fit it is possible to adjust it via ConditionByPredicate.describeEventsBy(..).

Issue: #855

Copy link
Contributor

@u3r u3r left a comment

Choose a reason for hiding this comment

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

All in all it looks good to me - just two remarks for my curiosity.

"Fixed it up a little" puts a different meaning to "a little" than I would though ;-)

Thanks for doing this - as announced I didn't find any time the passt few weeks for following up on this.

@codecholeric
Copy link
Collaborator Author

Okay, let's say s/a little/somewhat/ 🙈 Once I started I got more ideas on how to do things 😊 Hope you don't mind, I just want to release soon and I really liked having what we arrived at so far in there 🙂 And sometimes with async communication and time constraint on OSS this is quite challenging 😞

@u3r
Copy link
Contributor

u3r commented Jul 8, 2022

All good for me, looking forward to getting rid of some copy/pasta in our codebase with the new version!

There have been some leftovers from the Java 8 migration like obsolete explicit type arguments where it can be inferred.

Signed-off-by: Peter Gafert <peter.gafert@tngtech.com>
Signed-off-by: Peter Gafert <peter.gafert@tngtech.com>
The naming was a little inconsistent, `IsConditionByPredicate` took the details description as model for the name ("is/isn't"), while `HaveConditionByPredicate` took the condition description. Now they both take the condition description to derive the class name.

Signed-off-by: Peter Gafert <peter.gafert@tngtech.com>
@codecholeric codecholeric force-pushed the add-API-to-create-ArchConditions-from-predicates branch from e349294 to 2cc486e Compare July 8, 2022 18:00
Copy link
Member

@hankem hankem left a comment

Choose a reason for hiding this comment

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

That's gonna be very useful! (I love how ArchConditions could be shortened by almost 300 LoC.)

So far there has not been any straight forward way to turn a `DescribedPredicate` into an `ArchCondition`, even though the semantics are fairly similar (both determine if elements match a certain condition). The reason is, that `ArchCondition` needs more information than `DescribedPredicate`. While `DescribedPredicate` only needs to have some description to be displayed as part of the `ArchRule` text, `ArchCondition` additionally needs to describe each single event/violation that occurs. And the way how to do this depends on the predicate (take e.g. "does not *have* simple name 'Demo'" vs "is no enum" or "does not reside in a package 'com.demo'"). Thus, we have created a generic factory method `ArchCondition.from(predicate)` and two more convenient "sentence-like" factory methods `ArchConditions.{have/be}(predicate)` that can be used for most common cases. In any case if the event description does not fit it is possible to adjust it via `ConditionByPredicate.describeEventsBy(..)`.

Signed-off-by: Ulf Dreyer <ulf.dreyer@gmx.de>
Signed-off-by: Peter Gafert <peter.gafert@tngtech.com>
@codecholeric codecholeric force-pushed the add-API-to-create-ArchConditions-from-predicates branch from 450c1bd to 19839a1 Compare July 10, 2022 15:26
@codecholeric codecholeric merged commit 49f0722 into main Jul 10, 2022
@codecholeric codecholeric deleted the add-API-to-create-ArchConditions-from-predicates branch July 10, 2022 17:31
@nbrugger-tgm
Copy link

nbrugger-tgm commented Jul 11, 2022

This is huge, for the 1.0.0 Release I am definetly going to donate and if time let's me even contribute to this lovely project.

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.

4 participants