-
Notifications
You must be signed in to change notification settings - Fork 44
add utility to generate equals, hashCode and toString #278
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 utility to generate equals, hashCode and toString #278
Conversation
Commits are supposed to be reviewed in isolation. |
src/main/java/io/quarkus/gizmo2/impl/EqualsHashCodeToStringGenerator.java
Outdated
Show resolved
Hide resolved
src/main/java/io/quarkus/gizmo2/impl/EqualsHashCodeToStringGenerator.java
Outdated
Show resolved
Hide resolved
src/main/java/io/quarkus/gizmo2/impl/EqualsHashCodeToStringGenerator.java
Outdated
Show resolved
Hide resolved
src/main/java/io/quarkus/gizmo2/impl/EqualsHashCodeToStringGenerator.java
Outdated
Show resolved
Hide resolved
f132ca1
to
a8a2eb1
Compare
I think I addressed all the comments here, except of the |
a8a2eb1
to
dd034ac
Compare
Just to be sure: I simplified the |
|
||
LocalVar result = b0.define("result", Constant.of(1)); | ||
for (FieldDesc field : fields) { | ||
if (!field.owner().equals(thisClass)) { |
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.
You could conceivably include fields of a superclass, right?
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 didn't think about that, but you're right. I'm not really keen on removing the check, but I don't see a better way...
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.
So I'm thinking handling superclasses is out of scope, at least for now. The best way to handle superclasses would be to call equals()
(or hashCode()
; not sure about toString()
) on the superclass first, and then handle the fields of this class.
185f218
to
a69f993
Compare
Also, a few more validation methods were added.
The result type of the `InstanceOf` instruction is always `boolean`. It is _not_ the type of the argument.
This commit fixes code emission for the `Neg` instruction to also work with `byte`, `short` and `char` types. Argument validation was also added to the constructor, and the `Neg.writeCode()` method uses `impossibleSwitchCase()` to throw an error.
Use `impossibleSwitchCase()` in `Rel.writeCode()`.
This is mainly for discoverability in an IDE. Java has the `if` keyword, so presumably users will type `if` and expect to see the whole range of conditional generating methods. `unless()` doesn't show there, while `ifNot()` does.
The `ifNotInstanceOf()` method complements `ifInstanceOf()` in case the caller needs to do something when the given object is _not_ an instance of given type.
Fields don't always have to be created using class types; primitive types or array types are perfectly legal. So we need to correctly initialize the `Signature`, which isn't always a `ClassTypeSig`. Fortunately, `Signature` has the right factory method to create a signature out of a `ClassDesc`.
For now, we only remember descriptors of added members (instance/static fields, instance/static methods, constructors) and provide public access to them. In the future, we might want to remember all added creators, to be able to prevent adding the same member multiple times, but even in that case, we should still only expose access to descriptors.
First off, `arrayHashCode()` and `arrayToString()` methods were added to complement their `expr*` counterparts. The `expr*` methods never look for multidimensional arrays; they treat arrays as other reference types. The `array*` methods, on the other hand, always look for multidimensional arrays and use the proper `Arrays.deep*` methods if necessary.
This is an equivalent of `EqualsHashCodeToStringGenerator` from Gizmo 1.x.
a69f993
to
a3df338
Compare
This is an equivalent of
EqualsHashCodeToStringGenerator
from Gizmo 1.x.Resolves #258