diff --git a/build-config/src/main/resources/build-config/checkstyle.xml b/build-config/src/main/resources/build-config/checkstyle.xml index f0fcd480d..95a7edabb 100644 --- a/build-config/src/main/resources/build-config/checkstyle.xml +++ b/build-config/src/main/resources/build-config/checkstyle.xml @@ -186,6 +186,7 @@ + diff --git a/processor/src/main/java/org/mapstruct/ap/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/model/BeanMappingMethod.java index d8f342e56..159db6986 100644 --- a/processor/src/main/java/org/mapstruct/ap/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/model/BeanMappingMethod.java @@ -80,7 +80,7 @@ public class BeanMappingMethod extends MappingMethod { private List qualifiers; private NullValueMappingStrategyPrism nullValueMappingStrategy; private TypeMirror resultTypeMirror; - private final Collection existingVariableNames = new HashSet(); + private final Set existingVariableNames = new HashSet(); public Builder mappingContext(MappingBuilderContext mappingContext) { this.ctx = mappingContext; @@ -283,7 +283,7 @@ public class BeanMappingMethod extends MappingMethod { // as possible before we stop analysing propertyMapping = new PropertyMappingBuilder() .mappingContext( ctx ) - .souceMethod( method ) + .sourceMethod( method ) .targetWriteAccessor( targetWriteAccessor ) .targetReadAccessor( getTargetPropertyReadAccessor( mapping.getTargetName() ) ) .targetPropertyName( mapping.getTargetName() ) @@ -327,7 +327,7 @@ public class BeanMappingMethod extends MappingMethod { propertyMapping = new JavaExpressionMappingBuilder() .mappingContext( ctx ) - .souceMethod( method ) + .sourceMethod( method ) .javaExpression( mapping.getJavaExpression() ) .existingVariableNames( existingVariableNames ) .targetWriteAccessor( targetWriteAccessor ) @@ -405,7 +405,7 @@ public class BeanMappingMethod extends MappingMethod { newPropertyMapping = new PropertyMappingBuilder() .mappingContext( ctx ) - .souceMethod( method ) + .sourceMethod( method ) .targetWriteAccessor( targetProperty.getValue() ) .targetReadAccessor( getTargetPropertyReadAccessor( targetProperty.getKey() ) ) .targetPropertyName( targetProperty.getKey() ) @@ -469,7 +469,7 @@ public class BeanMappingMethod extends MappingMethod { PropertyMapping propertyMapping = new PropertyMappingBuilder() .mappingContext( ctx ) - .souceMethod( method ) + .sourceMethod( method ) .targetWriteAccessor( targetProperty.getValue() ) .targetReadAccessor( getTargetPropertyReadAccessor( targetProperty.getKey() ) ) .targetPropertyName( targetProperty.getKey() ) diff --git a/processor/src/main/java/org/mapstruct/ap/model/PropertyMapping.java b/processor/src/main/java/org/mapstruct/ap/model/PropertyMapping.java index 57ae69699..962c6b1b3 100644 --- a/processor/src/main/java/org/mapstruct/ap/model/PropertyMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/model/PropertyMapping.java @@ -19,7 +19,6 @@ package org.mapstruct.ap.model; import java.util.Arrays; -import java.util.Collection; import java.util.Collections; import java.util.List; import java.util.Set; @@ -68,45 +67,60 @@ public class PropertyMapping extends ModelElement { private final Assignment assignment; private final List dependsOn; - public static class PropertyMappingBuilder { + @SuppressWarnings("unchecked") + private static class MappingBuilderBase> { + + protected MappingBuilderContext ctx; + protected SourceMethod method; + protected ExecutableElement targetWriteAccessor; + protected ExecutableElement targetReadAccessor; + protected String targetPropertyName; + protected List dependsOn; + protected Set existingVariableNames; + + public T mappingContext(MappingBuilderContext mappingContext) { + this.ctx = mappingContext; + return (T) this; + } + + public T sourceMethod(SourceMethod sourceMethod) { + this.method = sourceMethod; + return (T) this; + } + + public T targetReadAccessor(ExecutableElement targetReadAccessor) { + this.targetReadAccessor = targetReadAccessor; + return (T) this; + } + + public T targetWriteAccessor(ExecutableElement targetWriteAccessor) { + this.targetWriteAccessor = targetWriteAccessor; + return (T) this; + } + + public T targetPropertyName(String targetPropertyName) { + this.targetPropertyName = targetPropertyName; + return (T) this; + } + + public T dependsOn(List dependsOn) { + this.dependsOn = dependsOn; + return (T) this; + } + + public T existingVariableNames(Set existingVariableNames) { + this.existingVariableNames = existingVariableNames; + return (T) this; + } + } + + public static class PropertyMappingBuilder extends MappingBuilderBase { // initial properties - private MappingBuilderContext ctx; - private SourceMethod method; - private ExecutableElement targetWriteAccessor; - private ExecutableElement targetReadAccessor; - private String targetPropertyName; private String dateFormat; private List qualifiers; private TypeMirror resultType; private SourceReference sourceReference; - private Collection existingVariableNames; - private List dependsOn; - - public PropertyMappingBuilder mappingContext(MappingBuilderContext mappingContext) { - this.ctx = mappingContext; - return this; - } - - public PropertyMappingBuilder souceMethod(SourceMethod sourceMethod) { - this.method = sourceMethod; - return this; - } - - public PropertyMappingBuilder targetReadAccessor(ExecutableElement targetReadAccessor) { - this.targetReadAccessor = targetReadAccessor; - return this; - } - - public PropertyMappingBuilder targetWriteAccessor(ExecutableElement targetWriteAccessor) { - this.targetWriteAccessor = targetWriteAccessor; - return this; - } - - public PropertyMappingBuilder targetPropertyName(String targetPropertyName) { - this.targetPropertyName = targetPropertyName; - return this; - } public PropertyMappingBuilder sourceReference(SourceReference sourceReference) { this.sourceReference = sourceReference; @@ -128,16 +142,6 @@ public class PropertyMapping extends ModelElement { return this; } - public PropertyMappingBuilder existingVariableNames(Collection existingVariableNames) { - this.existingVariableNames = existingVariableNames; - return this; - } - - public PropertyMappingBuilder dependsOn(List dependsOn) { - this.dependsOn = dependsOn; - return this; - } - private enum TargetWriteAccessorType { GETTER, SETTER, @@ -506,50 +510,18 @@ public class PropertyMapping extends ModelElement { } } - public static class ConstantMappingBuilder { + public static class ConstantMappingBuilder extends MappingBuilderBase { - private MappingBuilderContext ctx; - private SourceMethod method; private String constantExpression; - private String targetPropertyName; - private ExecutableElement targetWriteAccessor; - private ExecutableElement targetReadAccessor; private String dateFormat; private List qualifiers; private TypeMirror resultType; - private Collection existingVariableNames; - private List dependsOn; - - public ConstantMappingBuilder mappingContext(MappingBuilderContext mappingContext) { - this.ctx = mappingContext; - return this; - } - - public ConstantMappingBuilder sourceMethod(SourceMethod sourceMethod) { - this.method = sourceMethod; - return this; - } public ConstantMappingBuilder constantExpression(String constantExpression) { this.constantExpression = constantExpression; return this; } - public ConstantMappingBuilder targetWriteAccessor(ExecutableElement targetAccessor) { - this.targetWriteAccessor = targetAccessor; - return this; - } - - public ConstantMappingBuilder targetReadAccessor(ExecutableElement targetReadAccessor) { - this.targetReadAccessor = targetReadAccessor; - return this; - } - - public ConstantMappingBuilder targetPropertyName(String targetPropertyName) { - this.targetPropertyName = targetPropertyName; - return this; - } - public ConstantMappingBuilder dateFormat(String dateFormat) { this.dateFormat = dateFormat; return this; @@ -565,16 +537,6 @@ public class PropertyMapping extends ModelElement { return this; } - public ConstantMappingBuilder existingVariableNames(Collection existingVariableNames) { - this.existingVariableNames = existingVariableNames; - return this; - } - - public ConstantMappingBuilder dependsOn(List dependsOn) { - this.dependsOn = dependsOn; - return this; - } - public PropertyMapping build() { // source @@ -656,57 +618,15 @@ public class PropertyMapping extends ModelElement { } } - public static class JavaExpressionMappingBuilder { + public static class JavaExpressionMappingBuilder extends MappingBuilderBase { - private MappingBuilderContext ctx; - private SourceMethod method; private String javaExpression; - private Collection existingVariableNames; - private String targetPropertyName; - private List dependsOn; - private ExecutableElement targetWriteAccessor; - private ExecutableElement targetReadAccessor; - - public JavaExpressionMappingBuilder mappingContext(MappingBuilderContext mappingContext) { - this.ctx = mappingContext; - return this; - } - - public JavaExpressionMappingBuilder souceMethod(SourceMethod sourceMethod) { - this.method = sourceMethod; - return this; - } public JavaExpressionMappingBuilder javaExpression(String javaExpression) { this.javaExpression = javaExpression; return this; } - public JavaExpressionMappingBuilder targetWriteAccessor(ExecutableElement targetWriteAccessor) { - this.targetWriteAccessor = targetWriteAccessor; - return this; - } - - public JavaExpressionMappingBuilder targetReadAccessor(ExecutableElement targetReadAccessor) { - this.targetReadAccessor = targetReadAccessor; - return this; - } - - public JavaExpressionMappingBuilder existingVariableNames(Collection existingVariableNames) { - this.existingVariableNames = existingVariableNames; - return this; - } - - public JavaExpressionMappingBuilder targetPropertyName(String targetPropertyName) { - this.targetPropertyName = targetPropertyName; - return this; - } - - public JavaExpressionMappingBuilder dependsOn(List dependsOn) { - this.dependsOn = dependsOn; - return this; - } - public PropertyMapping build() { Assignment assignment = AssignmentFactory.createDirect( javaExpression );