Skip to content

Commit

Permalink
#1742 & #1661 refactoring and making builder optional
Browse files Browse the repository at this point in the history
Applying changes done in 3371058
  • Loading branch information
filiphr committed Sep 28, 2019
1 parent 55363df commit fe22c9b
Show file tree
Hide file tree
Showing 46 changed files with 882 additions and 482 deletions.
8 changes: 8 additions & 0 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,14 @@
<plugin>
<groupId>com.github.siom79.japicmp</groupId>
<artifactId>japicmp-maven-plugin</artifactId>
<configuration>
<parameter>
<excludes>
<!-- Exclude Builder from check see https://github.com/siom79/japicmp/issues/249 -->
<exclude>org.mapstruct.Builder</exclude>
</excludes>
</parameter>
</configuration>
</plugin>
</plugins>
</build>
Expand Down
8 changes: 8 additions & 0 deletions core/src/main/java/org/mapstruct/Builder.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,12 @@
* @return the method that needs to tbe invoked on the builder
*/
String buildMethod() default "build";

/**
* Toggling builders on / off. Builders are sometimes used solely for unit testing (fluent testdata)
* MapStruct will need to use the regular getters /setters in that case.
*
* @return when true, no builder patterns will be applied
*/
boolean disableBuilder() default false;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import javax.lang.model.element.AnnotationMirror;
import org.mapstruct.ap.internal.model.common.Assignment;
import org.mapstruct.ap.internal.model.common.BuilderType;
import org.mapstruct.ap.internal.model.common.ParameterBinding;
import org.mapstruct.ap.internal.model.common.SourceRHS;
import org.mapstruct.ap.internal.model.common.Type;
Expand Down Expand Up @@ -73,7 +74,7 @@ private boolean isDisableSubMappingMethodsGeneration() {
*
* @return See above
*/
Assignment createForgedAssignment(SourceRHS sourceRHS, ForgedMethod forgedMethod) {
Assignment createForgedAssignment(SourceRHS sourceRHS, BuilderType builderType, ForgedMethod forgedMethod) {

if ( ctx.getForgedMethodsUnderCreation().containsKey( forgedMethod ) ) {
return createAssignment( sourceRHS, ctx.getForgedMethodsUnderCreation().get( forgedMethod ) );
Expand All @@ -93,6 +94,7 @@ Assignment createForgedAssignment(SourceRHS sourceRHS, ForgedMethod forgedMethod
else {
forgedMappingMethod = new BeanMappingMethod.Builder()
.forgedMethod( forgedMethod )
.returnTypeBuilder( builderType )
.mappingContext( ctx )
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.mapstruct.ap.internal.model.common.Assignment;
import org.mapstruct.ap.internal.model.common.SourceRHS;
import org.mapstruct.ap.internal.model.common.Type;
import org.mapstruct.ap.internal.model.source.BeanMapping;
import org.mapstruct.ap.internal.model.source.ForgedMethod;
import org.mapstruct.ap.internal.model.source.ForgedMethodHistory;
import org.mapstruct.ap.internal.util.Strings;
Expand Down Expand Up @@ -63,7 +64,11 @@ Assignment forgeMapping(SourceRHS sourceRHS, Type sourceType, Type targetType) {
true
);

return createForgedAssignment( sourceRHS, forgedMethod );
return createForgedAssignment(
sourceRHS,
ctx.getTypeFactory().builderTypeFor( targetType, BeanMapping.builderPrismFor( method ) ),
forgedMethod
);
}

private String getName(Type sourceType, Type targetType) {
Expand Down
Loading

0 comments on commit fe22c9b

Please sign in to comment.