#3129: detect collection adders using Iterable setter/getter#3130
#3129: detect collection adders using Iterable setter/getter#3130sranka wants to merge 2 commits intomapstruct:mainfrom
Conversation
filiphr
left a comment
There was a problem hiding this comment.
I've left a comment on the LombokBuilderAccessorNamingStrategy. I think that the solution for this is fine (i.e. support adder methods for iterables). However, I would like to decouple this from Lombok entirely.
Can you also simplify the test classes a bit. This can be easily reproduced by having a class that looks like:
public class ImnutablePath {
private final List<String> edges = new ArrayList<>();
public Iterable<String> getEdges() {
return edges;
}
public void setEdges(Iterable<String> edges) {
this.edges.clear();
for(String edge: edges) {
this.edges.add(edge.toUpperCase());
}
}
public void addEdge(String edge) {
this.edges.add(edge);
}
}The tests should also be moved in the org.mapstruct.ap.test.collection.adder.AdderTest
There was a problem hiding this comment.
I don't understand the use of this class. There is an easy workaround for this if you use @Singular("add<singular"). If we are going in the territory of supporting @Singular properly then we need to also support something like @Singular("custom").
I would prefer that we do not go in that direction and only perhaps support adders for iterables as well.
| @Mappings({ | ||
| @Mapping(target = "edges", source = "edges"), | ||
| }) |
There was a problem hiding this comment.
This is obsolete. MapStruct is going to map this implicitly
|
@filiphr yeah, it looks similar, closing this PR |
Closes #3129
The code herein fixes the detection of collection adders to use a more generic
Iterableas a setter argument (or a getter return value). As consequence, a lombok generated builder setter (fluent) method:is now also considered as a candidate for searching of an associated adder:
Using the adders directly has a performance benefit when using lombok builders. The mapper implementation then does not need to create intermediary ArrayList values to map collection properties. For example, in place of this code (before this PR):
, the new mapper implementation is then optimal (this PR):