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 ClassInfo.canonicalConstructor() #419

Merged
merged 1 commit into from
Aug 8, 2024

Conversation

Ladicek
Copy link
Collaborator

@Ladicek Ladicek commented Aug 8, 2024

No description provided.

@Ladicek Ladicek added this to the 3.2.2 milestone Aug 8, 2024
*/
public MethodInfo canonicalConstructor() {
if (!isRecord()) {
return null;
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't it better to throw an exception here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In Jandex, it is customary to not throw but return a sentinel value in such cases. For example, ClassInfo.recordComponents() doesn't throw on non-records, it just returns an empty list.

We do throw an exception at the end of this method, but that's only for truly exceptional situations.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, java.lang.Class.getRecordComponents() also returns null. Sometimes we don't retun null, e.g. empty list in case of ClassInfo#enumConstants() but that's fine. TBH there should be probably RecordInfo and EnumInfo instead but 🤷.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, that would also require AnnotationInfo and InterfaceInfo for completeness :-)

Copy link
Contributor

Choose a reason for hiding this comment

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

Is there any way to make it clear from the name that this only works for records?

I'm not sure canonical will be clear enough for us laymen.

Copy link
Contributor

Choose a reason for hiding this comment

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

That is a good point. It should be canonicalRecordConstructor()!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It seems to me that canonicalConstructor() is enough, but canonicalRecordConstructor() is good too. Will rename.

Copy link
Contributor

Choose a reason for hiding this comment

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

Laymen thank you :).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, agreed. So far, only records have canonical constructors. People might wonder what a non-record canonical constructor is, but it doesn't exist. So +1 on the changed name.

@Ladicek Ladicek merged commit 6b0f3e3 into smallrye:main Aug 8, 2024
35 checks passed
@Ladicek Ladicek deleted the add-canonical-constructor branch August 8, 2024 12:50
This pull request was closed.
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