Add collection manipulation methods for union maps and union lists - #196
Merged
Conversation
Union maps and union lists now generate the same collection manipulation methods as entity maps and entity lists: - add, clear, insert, remove methods named after property (singularized) - Factory create methods for each entity type in the union - Removed setters for union collections to match entity collection behavior Changes: - AbstractCreateMethodsStage: Added createAddMethod, createClearMethod, createRemoveMethod, createInsertMethod for union types - CreateImplMethodsStage: Extended collection method implementations to handle union types with parent property tracking - AbstractJavaStage: Extended JavaType class to support union types in toJavaTypeString() and addImportsTo() - CreateReadersStage: Updated reader to use add methods instead of setters for union collections, with singularized property names - UnionMapTest: Added comprehensive test validating all collection methods work correctly All 10 integration tests pass.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Union maps and union lists now generate the same collection manipulation methods as entity maps and entity lists. This provides a consistent API for working with all types of collections in the generated models.
Problem
Previously, union maps and union lists only generated:
createmethods for each union typeEntity maps and entity lists generated:
createmethodsadd,clear,insert,removemethods (named after property)This inconsistency made union collections harder to use and less intuitive.
Solution
Updated the code generator to treat union maps/lists like entity maps/lists:
Generated Methods (example for property "schemas" with types
StandardSchema|MultiFormatSchema):addSchema(String name, MultiFormatSchemaStandardSchemaUnion value)- add to mapremoveSchema(String name)- remove from mapclearSchemas()- clear allgetSchemas()- get the mapinsertSchema(...)- insert at position (for lists)createStandardSchema()- factory for StandardSchemacreateMultiFormatSchema()- factory for MultiFormatSchemaMethods are named after the property name (singularized), not the union or entity type names.
Changes
AbstractCreateMethodsStage.java
createAddMethod,createClearMethod,createRemoveMethod,createInsertMethodcalls for union maps/listsCreateImplMethodsStage.java
AbstractJavaStage.java
JavaTypeclass to support union types intoJavaTypeString()andaddImportsTo()CreateReadersStage.java
handleUnionListPropertyandhandleUnionMapPropertyto use add methods instead of settersUnionMapTest.java
testCollectionMethods()test validating all new methods work correctlyTesting
All 10 integration tests pass: