Skip to content

Commit fe22c9b

Browse files
committed
mapstruct#1742 & mapstruct#1661 refactoring and making builder optional
Applying changes done in 3371058
1 parent 55363df commit fe22c9b

46 files changed

Lines changed: 882 additions & 482 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

core/pom.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,14 @@
104104
<plugin>
105105
<groupId>com.github.siom79.japicmp</groupId>
106106
<artifactId>japicmp-maven-plugin</artifactId>
107+
<configuration>
108+
<parameter>
109+
<excludes>
110+
<!-- Exclude Builder from check see https://github.com/siom79/japicmp/issues/249 -->
111+
<exclude>org.mapstruct.Builder</exclude>
112+
</excludes>
113+
</parameter>
114+
</configuration>
107115
</plugin>
108116
</plugins>
109117
</build>

core/src/main/java/org/mapstruct/Builder.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,12 @@
2929
* @return the method that needs to tbe invoked on the builder
3030
*/
3131
String buildMethod() default "build";
32+
33+
/**
34+
* Toggling builders on / off. Builders are sometimes used solely for unit testing (fluent testdata)
35+
* MapStruct will need to use the regular getters /setters in that case.
36+
*
37+
* @return when true, no builder patterns will be applied
38+
*/
39+
boolean disableBuilder() default false;
3240
}

processor/src/main/java/org/mapstruct/ap/internal/model/AbstractBaseBuilder.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import javax.lang.model.element.AnnotationMirror;
99
import org.mapstruct.ap.internal.model.common.Assignment;
10+
import org.mapstruct.ap.internal.model.common.BuilderType;
1011
import org.mapstruct.ap.internal.model.common.ParameterBinding;
1112
import org.mapstruct.ap.internal.model.common.SourceRHS;
1213
import org.mapstruct.ap.internal.model.common.Type;
@@ -73,7 +74,7 @@ private boolean isDisableSubMappingMethodsGeneration() {
7374
*
7475
* @return See above
7576
*/
76-
Assignment createForgedAssignment(SourceRHS sourceRHS, ForgedMethod forgedMethod) {
77+
Assignment createForgedAssignment(SourceRHS sourceRHS, BuilderType builderType, ForgedMethod forgedMethod) {
7778

7879
if ( ctx.getForgedMethodsUnderCreation().containsKey( forgedMethod ) ) {
7980
return createAssignment( sourceRHS, ctx.getForgedMethodsUnderCreation().get( forgedMethod ) );
@@ -93,6 +94,7 @@ Assignment createForgedAssignment(SourceRHS sourceRHS, ForgedMethod forgedMethod
9394
else {
9495
forgedMappingMethod = new BeanMappingMethod.Builder()
9596
.forgedMethod( forgedMethod )
97+
.returnTypeBuilder( builderType )
9698
.mappingContext( ctx )
9799
.build();
98100
}

processor/src/main/java/org/mapstruct/ap/internal/model/AbstractMappingMethodBuilder.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import org.mapstruct.ap.internal.model.common.Assignment;
99
import org.mapstruct.ap.internal.model.common.SourceRHS;
1010
import org.mapstruct.ap.internal.model.common.Type;
11+
import org.mapstruct.ap.internal.model.source.BeanMapping;
1112
import org.mapstruct.ap.internal.model.source.ForgedMethod;
1213
import org.mapstruct.ap.internal.model.source.ForgedMethodHistory;
1314
import org.mapstruct.ap.internal.util.Strings;
@@ -63,7 +64,11 @@ Assignment forgeMapping(SourceRHS sourceRHS, Type sourceType, Type targetType) {
6364
true
6465
);
6566

66-
return createForgedAssignment( sourceRHS, forgedMethod );
67+
return createForgedAssignment(
68+
sourceRHS,
69+
ctx.getTypeFactory().builderTypeFor( targetType, BeanMapping.builderPrismFor( method ) ),
70+
forgedMethod
71+
);
6772
}
6873

6974
private String getName(Type sourceType, Type targetType) {

0 commit comments

Comments
 (0)