Skip to content

Commit 6b49c83

Browse files
author
sjaakd
committed
mapstruct#1998 simplify usage of inheritance of annotation fields
1 parent b84526b commit 6b49c83

38 files changed

Lines changed: 1082 additions & 936 deletions

processor/src/main/java/org/mapstruct/ap/internal/conversion/CreateDecimalFormat.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public Type getReturnType() {
5252
}
5353

5454
@Override
55-
public MappingMethodOptions getMappingOptions() {
55+
public MappingMethodOptions getOptions() {
5656
return MappingMethodOptions.empty();
5757
}
5858
}

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
package org.mapstruct.ap.internal.model;
77

88
import javax.lang.model.element.AnnotationMirror;
9+
910
import org.mapstruct.ap.internal.model.common.Assignment;
1011
import org.mapstruct.ap.internal.model.common.BuilderType;
1112
import org.mapstruct.ap.internal.model.common.ParameterBinding;
1213
import org.mapstruct.ap.internal.model.common.SourceRHS;
1314
import org.mapstruct.ap.internal.model.common.Type;
1415
import org.mapstruct.ap.internal.model.source.MappingMethodUtils;
1516
import org.mapstruct.ap.internal.model.source.Method;
16-
import org.mapstruct.ap.internal.util.MapperOptions;
1717
import org.mapstruct.ap.internal.util.Message;
1818

1919
/**
@@ -60,8 +60,7 @@ boolean canGenerateAutoSubMappingBetween(Type sourceType, Type targetType) {
6060
}
6161

6262
private boolean isDisableSubMappingMethodsGeneration() {
63-
MapperOptions configuration = MapperOptions.getInstanceOn( ctx.getMapperTypeElement() );
64-
return configuration.isDisableSubMappingMethodsGeneration();
63+
return method.getOptions().getMapper().isDisableSubMappingMethodsGeneration();
6564
}
6665

6766
/**
@@ -86,7 +85,7 @@ Assignment createForgedAssignment(SourceRHS sourceRHS, BuilderType builderType,
8685
if ( MappingMethodUtils.isEnumMapping( forgedMethod ) ) {
8786
forgedMappingMethod = new ValueMappingMethod.Builder()
8887
.method( forgedMethod )
89-
.valueMappings( forgedMethod.getMappingOptions().getValueMappings() )
88+
.valueMappings( forgedMethod.getOptions().getValueMappings() )
9089
.mappingContext( ctx )
9190
.build();
9291
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +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.BeanMappingOptions;
11+
import org.mapstruct.ap.internal.prism.BuilderPrism;
1212
import org.mapstruct.ap.internal.util.Strings;
1313

1414
import static org.mapstruct.ap.internal.model.ForgedMethod.forElementMapping;
@@ -54,12 +54,12 @@ Assignment forgeMapping(SourceRHS sourceRHS, Type sourceType, Type targetType) {
5454
sourceRHS.getSourceErrorMessagePart() );
5555

5656
ForgedMethod forgedMethod = forElementMapping( name, sourceType, targetType, method, forgedHistory, true );
57+
BuilderPrism builderPrism = method.getOptions().getBeanMapping().getBuilderPrism();
5758

5859
return createForgedAssignment(
59-
sourceRHS,
60-
ctx.getTypeFactory()
61-
.builderTypeFor( targetType, BeanMappingOptions.builderPrismFor( method ) ),
62-
forgedMethod
60+
sourceRHS,
61+
ctx.getTypeFactory().builderTypeFor( targetType, builderPrism ),
62+
forgedMethod
6363
);
6464
}
6565

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

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,11 @@
3737
import org.mapstruct.ap.internal.model.dependency.GraphAnalyzer.GraphAnalyzerBuilder;
3838
import org.mapstruct.ap.internal.model.source.BeanMappingOptions;
3939
import org.mapstruct.ap.internal.model.source.MappingOptions;
40-
import org.mapstruct.ap.internal.model.source.MappingMethodOptions;
4140
import org.mapstruct.ap.internal.model.source.Method;
4241
import org.mapstruct.ap.internal.model.source.SelectionParameters;
4342
import org.mapstruct.ap.internal.model.source.SourceMethod;
4443
import org.mapstruct.ap.internal.prism.CollectionMappingStrategyPrism;
45-
import org.mapstruct.ap.internal.prism.NullValueMappingStrategyPrism;
4644
import org.mapstruct.ap.internal.prism.ReportingPolicyPrism;
47-
import org.mapstruct.ap.internal.util.MapperOptions;
4845
import org.mapstruct.ap.internal.util.Message;
4946
import org.mapstruct.ap.internal.util.Strings;
5047
import org.mapstruct.ap.internal.util.accessor.Accessor;
@@ -121,7 +118,7 @@ public Builder forgedMethod(ForgedMethod forgedMethod) {
121118

122119
public BeanMappingMethod build() {
123120

124-
BeanMappingOptions beanMapping = method.getMappingOptions().getBeanMapping();
121+
BeanMappingOptions beanMapping = method.getOptions().getBeanMapping();
125122
SelectionParameters selectionParameters = beanMapping != null ? beanMapping.getSelectionParameters() : null;
126123

127124
/* the return type that needs to be constructed (new or factorized), so for instance: */
@@ -161,7 +158,7 @@ else if ( !method.isUpdateMethod() ) {
161158
/* the type that needs to be used in the mapping process as target */
162159
Type resultTypeToMap = returnTypeToConstruct == null ? method.getResultType() : returnTypeToConstruct;
163160

164-
CollectionMappingStrategyPrism cms = this.method.getMapperConfiguration().getCollectionMappingStrategy();
161+
CollectionMappingStrategyPrism cms = this.method.getOptions().getMapper().getCollectionMappingStrategy();
165162

166163
// determine accessors
167164
Map<String, Accessor> accessors = resultTypeToMap.getPropertyWriteAccessors( cms );
@@ -216,9 +213,10 @@ else if ( !method.isUpdateMethod() ) {
216213
reportErrorForUnmappedSourcePropertiesIfRequired();
217214

218215
// mapNullToDefault
219-
NullValueMappingStrategyPrism nullValueMappingStrategy =
220-
beanMapping != null ? beanMapping.getNullValueMappingStrategy() : null;
221-
boolean mapNullToDefault = method.getMapperConfiguration().isMapToDefault( nullValueMappingStrategy );
216+
boolean mapNullToDefault = method.getOptions()
217+
.getBeanMapping()
218+
.getNullValueMappingStrategy()
219+
.isReturnDefault();
222220

223221
// sort
224222
sortPropertyMappingsByDependencies();
@@ -388,7 +386,7 @@ private boolean canResultTypeFromBeanMappingBeConstructed(Type resultType) {
388386
if ( resultType.isAbstract() ) {
389387
ctx.getMessager().printMessage(
390388
method.getExecutable(),
391-
method.getMappingOptions().getBeanMapping().getMirror(),
389+
method.getOptions().getBeanMapping().getMirror(),
392390
BEANMAPPING_ABSTRACT,
393391
resultType,
394392
method.getResultType()
@@ -398,7 +396,7 @@ private boolean canResultTypeFromBeanMappingBeConstructed(Type resultType) {
398396
else if ( !resultType.isAssignableTo( method.getResultType() ) ) {
399397
ctx.getMessager().printMessage(
400398
method.getExecutable(),
401-
method.getMappingOptions().getBeanMapping().getMirror(),
399+
method.getOptions().getBeanMapping().getMirror(),
402400
BEANMAPPING_NOT_ASSIGNABLE,
403401
resultType,
404402
method.getResultType()
@@ -408,7 +406,7 @@ else if ( !resultType.isAssignableTo( method.getResultType() ) ) {
408406
else if ( !resultType.hasEmptyAccessibleConstructor() ) {
409407
ctx.getMessager().printMessage(
410408
method.getExecutable(),
411-
method.getMappingOptions().getBeanMapping().getMirror(),
409+
method.getOptions().getBeanMapping().getMirror(),
412410
Message.GENERAL_NO_SUITABLE_CONSTRUCTOR,
413411
resultType
414412
);
@@ -630,8 +628,7 @@ else if ( mapping.getJavaExpression() != null ) {
630628
.defaultValue( mapping.getDefaultValue() )
631629
.defaultJavaExpression( mapping.getDefaultJavaExpression() )
632630
.mirror( mapping.getMirror() )
633-
.nullValueCheckStrategy( mapping.getNullValueCheckStrategy() )
634-
.nullValuePropertyMappingStrategy( mapping.getNullValuePropertyMappingStrategy() )
631+
.options( mapping )
635632
.build();
636633
handledTargets.add( targetPropertyName );
637634
unprocessedSourceParameters.remove( sourceRef.getParameter() );
@@ -732,6 +729,7 @@ private void applyPropertyNameBasedMapping(List<SourceReference> sourceReference
732729
.sourceReference( sourceRef )
733730
.existingVariableNames( existingVariableNames )
734731
.forgeMethodWithMappingReferences( mappingRefs )
732+
.options( method.getOptions().getBeanMapping() )
735733
.build();
736734

737735
unprocessedSourceParameters.remove( sourceRef.getParameter() );
@@ -777,6 +775,7 @@ private void applyParameterNameBasedMapping() {
777775
.sourceReference( sourceRef )
778776
.existingVariableNames( existingVariableNames )
779777
.forgeMethodWithMappingReferences( mappingRefs )
778+
.options( method.getOptions().getBeanMapping() )
780779
.build();
781780

782781
propertyMappings.add( propertyMapping );
@@ -828,15 +827,7 @@ private ReportingPolicyPrism getUnmappedTargetPolicy() {
828827
if ( mappingReferences.isForForgedMethods() ) {
829828
return ReportingPolicyPrism.IGNORE;
830829
}
831-
MappingMethodOptions mappingOptions = method.getMappingOptions();
832-
if ( mappingOptions.getBeanMapping() != null &&
833-
mappingOptions.getBeanMapping().getReportingPolicy() != null ) {
834-
return mappingOptions.getBeanMapping().getReportingPolicy();
835-
}
836-
837-
MapperOptions mapperSettings = MapperOptions.getInstanceOn( ctx.getMapperTypeElement() );
838-
839-
return mapperSettings.unmappedTargetPolicy( ctx.getOptions() );
830+
return method.getOptions().getMapper().unmappedTargetPolicy();
840831
}
841832

842833
private void reportErrorForUnmappedTargetPropertiesIfRequired() {
@@ -917,9 +908,7 @@ private ReportingPolicyPrism getUnmappedSourcePolicy() {
917908
if ( mappingReferences.isForForgedMethods() ) {
918909
return ReportingPolicyPrism.IGNORE;
919910
}
920-
MapperOptions mapperSettings = MapperOptions.getInstanceOn( ctx.getMapperTypeElement() );
921-
922-
return mapperSettings.unmappedSourcePolicy();
911+
return method.getOptions().getMapper().unmappedSourcePolicy();
923912
}
924913

925914
private void reportErrorForUnmappedSourcePropertiesIfRequired() {

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import javax.lang.model.element.ExecutableElement;
1010

1111
import org.mapstruct.ap.internal.model.common.BuilderType;
12-
import org.mapstruct.ap.internal.model.source.BeanMappingOptions;
1312
import org.mapstruct.ap.internal.model.source.Method;
1413
import org.mapstruct.ap.internal.prism.BuilderPrism;
1514
import org.mapstruct.ap.internal.util.Message;
@@ -35,7 +34,7 @@ public static MethodReference getBuilderFinisherMethod(Method method, BuilderTyp
3534
return null;
3635
}
3736

38-
BuilderPrism builderMapping = BeanMappingOptions.builderPrismFor( method );
37+
BuilderPrism builderMapping = method.getOptions().getBeanMapping().getBuilderPrism();
3938
if ( builderMapping == null && buildMethods.size() == 1 ) {
4039
return MethodReference.forMethodCall( first( buildMethods ).getSimpleName().toString() );
4140
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public CollectionAssignmentBuilder nullValuePropertyMappingStrategy( NullValuePr
127127
public Assignment build() {
128128
Assignment result = assignment;
129129

130-
CollectionMappingStrategyPrism cms = method.getMapperConfiguration().getCollectionMappingStrategy();
130+
CollectionMappingStrategyPrism cms = method.getOptions().getMapper().getCollectionMappingStrategy();
131131
boolean targetImmutable = cms == CollectionMappingStrategyPrism.TARGET_IMMUTABLE || targetReadAccessor == null;
132132

133133
if ( targetAccessorType == AccessorType.SETTER || targetAccessorType == AccessorType.FIELD ) {

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

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
*/
66
package org.mapstruct.ap.internal.model;
77

8-
import static org.mapstruct.ap.internal.util.Collections.first;
9-
108
import java.util.Collection;
119
import java.util.HashSet;
1210
import java.util.List;
@@ -19,10 +17,11 @@
1917
import org.mapstruct.ap.internal.model.source.Method;
2018
import org.mapstruct.ap.internal.model.source.SelectionParameters;
2119
import org.mapstruct.ap.internal.model.source.selector.SelectionCriteria;
22-
import org.mapstruct.ap.internal.prism.NullValueMappingStrategyPrism;
2320
import org.mapstruct.ap.internal.util.Message;
2421
import org.mapstruct.ap.internal.util.Strings;
2522

23+
import static org.mapstruct.ap.internal.util.Collections.first;
24+
2625
/**
2726
* Builder that can be used to build {@link ContainerMappingMethod}(s).
2827
*
@@ -36,7 +35,6 @@ public abstract class ContainerMappingMethodBuilder<B extends ContainerMappingMe
3635

3736
private SelectionParameters selectionParameters;
3837
private FormattingParameters formattingParameters;
39-
private NullValueMappingStrategyPrism nullValueMappingStrategy;
4038
private String errorMessagePart;
4139
private String callingContextTargetPropertyName;
4240

@@ -55,11 +53,6 @@ public B selectionParameters(SelectionParameters selectionParameters) {
5553
return myself;
5654
}
5755

58-
public B nullValueMappingStrategy(NullValueMappingStrategyPrism nullValueMappingStrategy) {
59-
this.nullValueMappingStrategy = nullValueMappingStrategy;
60-
return myself;
61-
}
62-
6356
public B callingContextTargetPropertyName(String callingContextTargetPropertyName) {
6457
this.callingContextTargetPropertyName = callingContextTargetPropertyName;
6558
return myself;
@@ -122,10 +115,10 @@ public final M build() {
122115
assignment = getWrapper( assignment, method );
123116

124117
// mapNullToDefault
125-
boolean mapNullToDefault = false;
126-
if ( method.getMapperConfiguration() != null ) {
127-
mapNullToDefault = method.getMapperConfiguration().isMapToDefault( nullValueMappingStrategy );
128-
}
118+
boolean mapNullToDefault = method.getOptions()
119+
.getIterableMapping()
120+
.getNullValueMappingStrategy()
121+
.isReturnDefault();
129122

130123
MethodReference factoryMethod = null;
131124
if ( !method.isUpdateMethod() ) {

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

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,13 @@
1212
import java.util.Objects;
1313
import javax.lang.model.element.ExecutableElement;
1414

15+
import org.mapstruct.ap.internal.model.beanmapping.MappingReferences;
1516
import org.mapstruct.ap.internal.model.common.Accessibility;
1617
import org.mapstruct.ap.internal.model.common.Parameter;
1718
import org.mapstruct.ap.internal.model.common.Type;
1819
import org.mapstruct.ap.internal.model.source.MappingMethodOptions;
19-
import org.mapstruct.ap.internal.model.beanmapping.MappingReferences;
2020
import org.mapstruct.ap.internal.model.source.Method;
2121
import org.mapstruct.ap.internal.model.source.ParameterProvidedMethods;
22-
import org.mapstruct.ap.internal.util.MapperOptions;
2322
import org.mapstruct.ap.internal.util.Strings;
2423

2524
/**
@@ -322,11 +321,6 @@ public Type getDefiningType() {
322321
return null;
323322
}
324323

325-
@Override
326-
public MapperOptions getMapperConfiguration() {
327-
return basedOn.getMapperConfiguration();
328-
}
329-
330324
@Override
331325
public boolean isUpdateMethod() {
332326
return getMappingTargetParameter() != null;
@@ -343,8 +337,8 @@ public boolean isObjectFactory() {
343337
}
344338

345339
@Override
346-
public MappingMethodOptions getMappingOptions() {
347-
return basedOn.getMappingOptions();
340+
public MappingMethodOptions getOptions() {
341+
return basedOn.getOptions();
348342
}
349343

350344
public MappingReferences getMappingReferences() {

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import org.mapstruct.ap.internal.model.common.Type;
1919
import org.mapstruct.ap.internal.model.source.Method;
2020
import org.mapstruct.ap.internal.model.source.ParameterProvidedMethods;
21-
import org.mapstruct.ap.internal.util.MapperOptions;
2221
import org.mapstruct.ap.internal.util.Strings;
2322

2423
/**
@@ -237,11 +236,6 @@ public Type getDefiningType() {
237236
return null;
238237
}
239238

240-
@Override
241-
public MapperOptions getMapperConfiguration() {
242-
return null;
243-
}
244-
245239
@Override
246240
public boolean isLifecycleCallbackMethod() {
247241
return false;

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,8 @@ public MapMappingMethod build() {
177177
}
178178

179179
// mapNullToDefault
180-
boolean mapNullToDefault = false;
181-
if ( method.getMapperConfiguration() != null ) {
182-
mapNullToDefault = method.getMapperConfiguration().isMapToDefault( nullValueMappingStrategy );
183-
}
180+
boolean mapNullToDefault =
181+
method.getOptions().getMapMapping().getNullValueMappingStrategy().isReturnDefault();
184182

185183
MethodReference factoryMethod = null;
186184
if ( !method.isUpdateMethod() ) {

0 commit comments

Comments
 (0)