Add support for Java records (JEP 395, Java 16+)#126
Conversation
This commit adds: - EClassType.RECORD for record type declarations - JRecordComponent class to represent record components - _record() methods in IJClassContainer to create records - recordComponent() and recordComponentVararg() methods in JDefinedClass - compactConstructor() for validation-only constructors - isRecord() helper method - JDocComment.addParam(JRecordComponent) for javadoc support Tests cover: basic records, empty records, object/array/ varargs components, generics, annotations, compact and canonical constructors, methods, static members, nested records, and javadoc.
|
Claude wrote most of this code. I guided claude to stick with project conventions, and also guided the strategy for how records should fit into the current project. You'll see that this implementation follows a similar pattern to other kinds of class (e.g. enum), where we don't define a new JRecord but instead this just a new class type, and in this kind of class has record 'components' (as per https://openjdk.org/jeps/395). Feedback and ideas on this very welcome. I'm thinking I will migrate jsonschema2pojo to use this library so this PR will help me with supporting records there. Sealed types would be next. |
- Change from ValueEnforcer to explicit IllegalStateException throws - Fix missing semicolons in throw statements - Fix error message in recordComponentVararg() - Add tests for calling record methods on non-record classes - Add test for duplicate compact constructor
|
Added a new commit here with some additional tests for unhappy paths and exception cases. I'll rebase all this into one clean commit once we're happy to merge. |
|
Thanks - looks pretty good :) |
This commit adds:
Tests cover: basic records, empty records, object/array/ varargs components, generics, annotations, compact and canonical constructors, methods, static members, nested records, and javadoc.