add support for generics in Arrays and fix initialization of multidimensional arrays#4050
Open
hduelme wants to merge 1 commit into
Conversation
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.
While reviewing #4045 and looking for places where objects are initialized, I came across generics with arrays.
Bug fixes included in this PR:
Creation of arrays with generics
Turns out generics are not allowed on an array constructor. MapStruct generates:
return new CustomerGenerics<String>[0];I centralized array initialization with size handling in
constructArrayTypend removed the generics there. The same issue existed when mapping Streams to arrays.Missing generics on method creation
MapStruct currently drops generics on generated methods.
From:
CustomerGenerics<String>[] array(CustomerGenerics<String>[] a);it generates:
public CustomerGenerics[] array(CustomerGenerics[] a) {I fixed this by reading the generics from the first component type that is not an array. This also required implementing
withoutBounds()andreplaceSuperBoundWith()for arraysWrong creation of default arrays for multidimensional arrays
Currently MapStruct writes the size in the last brackets, but it needs to be in the first:
return new byte[][0];Multidimensional arrays do not work correctly with generics or varargs
I fixed the implementation in
Type.ftl: first the base type, then the generics, then the array dimensions, and finally the last array or varargs declaration.I added tests for my changes to the existing test suite. It might make sense to move
Issue895Testto the array package, since it directly tests whether multidimensional arrays work correctly.