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

Code generator record and enum updates. #7339

Merged
merged 1 commit into from
May 7, 2024

Conversation

mbien
Copy link
Member

@mbien mbien commented Apr 26, 2024

Implement basic record code generation features.

image

records:

  • javac generates final methods for records unless they are already in the code
    • code can't override them which complicates things, but it can replace them using the abstract method impl generator
  • made equals, hashCode and toString generators record aware
  • disabled getter/setter and property generator for records (record accessors are regular method overrrides)

enums:

  • toString generator supports now enums

fixes #7167

@mbien mbien added Java [ci] enable extra Java tests (java.completion, java.source.base, java.hints, refactoring.java, form) ci:dev-build [ci] produce a dev-build zip artifact (7 days expiration, see link on workflow summary page) labels Apr 26, 2024
@mbien mbien added this to the NB22 milestone Apr 26, 2024
@mbien mbien force-pushed the fix-record-override_delivery branch from 0ac4822 to e086f04 Compare April 26, 2024 23:26
@mbien mbien added the ci:all-tests [ci] enable all tests label Apr 27, 2024
@mbien mbien force-pushed the fix-record-override_delivery branch from e086f04 to 2e166d1 Compare April 27, 2024 00:18
@mbien mbien linked an issue May 2, 2024 that may be closed by this pull request
@mbien mbien force-pushed the fix-record-override_delivery branch from 2e166d1 to 09e12a3 Compare May 3, 2024 01:33
@mbien mbien changed the title Code generator record updates. Code generator record and enum updates. May 3, 2024
@mbien mbien marked this pull request as ready for review May 3, 2024 01:41
@mbien
Copy link
Member Author

mbien commented May 3, 2024

i went back and forth with implementing record accessors as getter generator or implements / override generator.

Ended up implementing it as override generator, since:

  • JEP 395 uses the term component accessors, getters are elements of the bean pattern and records are no beans
  • they are already there, so override makes most sense semantically (technically it is replacing the impl since javac won't generate the (final) synthetic method if it already exists)

I still don't like that the templates for simple tasks like those here are user customizable since there is nothing to customize other than having to remove a link.

@mbien mbien requested review from matthiasblaesing and lahodaj May 3, 2024 02:11
@mbien mbien removed the ci:all-tests [ci] enable all tests label May 3, 2024
@mbien mbien requested a review from dbalek May 3, 2024 02:38
Copy link
Contributor

@matthiasblaesing matthiasblaesing left a comment

Choose a reason for hiding this comment

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

Looks good to me. Thank you!

@lahodaj
Copy link
Contributor

lahodaj commented May 6, 2024

Will take a look later today, thanks for working on this!

@mbien
Copy link
Member Author

mbien commented May 6, 2024

found a small issue where the equals/hashcode generator doesn't check if the methods are already there in the record, will fix it in a moment.

diff: https://github.com/apache/netbeans/compare/09e12a32b98f0d9d26dc9e80249c24211a613948..fa3bc2a302fe103295b7d5d94b10ced1162114f3
and: https://github.com/apache/netbeans/compare/fa3bc2a302fe103295b7d5d94b10ced1162114f3..8a4bbd44b1064b3f6108592acd135044a9ed6a72

@mbien mbien force-pushed the fix-record-override_delivery branch 2 times, most recently from fa3bc2a to 8a4bbd4 Compare May 6, 2024 14:33
Copy link
Contributor

@lahodaj lahodaj left a comment

Choose a reason for hiding this comment

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

Makes sense to me, thanks!

record accessors:
 - javac generates final methods for records unless they are already
   in the code
 - code can't override them, but it can replace them using the abstract
   method impl generator

record other generators:
 - made equals, hashcode and toString generators record aware
 - disabled getter/setter and property generator for records

enums:
 - toString support for enums
@mbien mbien force-pushed the fix-record-override_delivery branch from 8a4bbd4 to 7928dc1 Compare May 6, 2024 16:45
@ebarboni ebarboni merged commit a6239c6 into apache:delivery May 7, 2024
37 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ci:dev-build [ci] produce a dev-build zip artifact (7 days expiration, see link on workflow summary page) Java [ci] enable extra Java tests (java.completion, java.source.base, java.hints, refactoring.java, form)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

override-method for records should suggest all overridable methods
4 participants