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

Generate Equality Check for entities #799

Merged
merged 4 commits into from
Jul 1, 2024

Conversation

badetitou
Copy link
Member

@badetitou badetitou commented Jun 28, 2024

This PR aims to add in the generator the code to generate equality checks (method = and hash).
We keep the current default behavior -> no breaking change possible :)

I propose adding a method named: withEqualityCheckOn: that takes the list of properties as input to check for equality.
It then generates the = and hash methods considering this list.

I have modified FamixTest4Generator to take into consideration this update.
For instance, I added to person a firstName and lastName. And I added the quality check on them

	person property: #firstName type: #String.
	person property: #lastName type: #String.
	person withEqualityCheckOn: { #firstName. #lastName }.

The same for book with an id

I update the setup to add identity information. And I added the test testEqualityStudent to particularly test this feature

For method =

The generation follows this pattern:

= aFamixTest4Person 

	<generated>
	^ aFamixTest4Person firstName = self firstName and: [ aFamixTest4Person lastName = self lastName] 

And for hash

hash

	<generated>
	^ self firstName hash bitXor: self lastName hash 

I based this template on existing methods in the system

@ClotildeToullec ClotildeToullec merged commit d0830d6 into development Jul 1, 2024
4 checks passed
@ClotildeToullec ClotildeToullec deleted the can-generate-equality-check branch July 1, 2024 14:42
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.

2 participants